-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup lifetime management in OSX FileSystemWatcher #52019
Conversation
Tagging subscribers to this area: @carlossanlop |
CFTimeInterval latency, | ||
FSEventStreamCreateFlags flags) | ||
{ | ||
return FSEventStreamCreate(IntPtr.Zero, cb, IntPtr.Zero, pathsToWatch, sinceWhen, latency, flags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Low value wrapper.
@@ -138,6 +138,9 @@ private sealed class RunningInstance | |||
// Callback delegate for the EventStream events | |||
private readonly Interop.EventStream.FSEventStreamCallback _callback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new GCHandle is a counterpart for this delegate. The RunningInstance has to be kept alive for as long as the marshalled delegate is in use. There was nothing to guarantee that before this change.
I have also looked into replacing the delegate by a function pointer, but that was more involved change so I have abandoned it.
try | ||
{ | ||
// When we get here, we've requested to stop so cleanup the EventStream and unschedule from the RunLoop | ||
Interop.EventStream.FSEventStreamStop(eventStream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FSEventStreamStop does not throw any exceptions. This try/finally does not look necessary. It may be a left over from some thread abort hardening.
SafeCreateHandle? path = null; | ||
SafeCreateHandle? arrPaths = null; | ||
bool cleanupGCHandle = false; | ||
try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactoring is to ensure that everything gets disposed when anything fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, big thanks for fixing this @jkotas !
May fix #30056