-
Notifications
You must be signed in to change notification settings - Fork 4.9k
close _eventStream when stopping watcher #41013
Conversation
|
You can probably use CFGetRetainCount before releasing the last ref to validate it's 1. |
|
Can confirm, mono side is fixed too 🎉 |
src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs
Outdated
Show resolved
Hide resolved
|
For 2.2 we'll need the usual PR with template, and mail to netcoreship. Thanks @wfurt. |
|
test failures in System.Security.Cryptography are unrelated. Please let me know if there is anything outstanding @JeremyKuhne and @stephentoub. |
|
@carlossanlop perhaps you can review? |
| { | ||
| _cancellation = null; | ||
| token.Cancel(); | ||
| token.Dispose(); |
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.
@wfurt I have a question: why do we only cancel and dispose the token here? The RunningInstance class received a copy of this token in its constructor, so why not perform these two actions inside CancellationCallback too? (follow up of Marius' question).
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.
CancellationCallback() did not do anything with the token. It is StartRaisingEvents() where token was created and symmetrically StopRaisingEvents() where token is destroyed. Existing _cancellation = null should be sufficient IMHO to dispose token. I only add explicit Dispose() call to make it explicit and not wait for GC. I did not want to introduce different life cycle for the token and worry about what changed.
carlossanlop
left a comment
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.
Left a question.
Would it make sense to add unit tests to verify this change?
The build failed. Do you know what was the cause?
|
@wfurt, what's the status of this PR? Can it be made ready to merge, or closed? |
|
Tests are failing in System.Security.Cryptography on OSX and x86 Windows. That seems unrelated to this change. As far as the test I could not come up with one I would like. Best I think I can do is to create and destroy watcher in loop and make loop count bigger than default handle limit. But CI does manipulate limits AFAIK and well as that may differ across systems. Also tests trying to exhaust system resources are potentially dangerous. Let me know @carlossanlop if you have suggestions. |
I noticed the original issue #40888 has a small file watcher test here: https://github.com/mrward/test-file-watcher-dispose/blob/master/Program.cs Would it make sense to write a unit test that looks somewhat like in that code, or would we encounter the CI limit you mentioned, @wfurt ? |
|
I know this is icky, but what if we had something like: var streamHandle = // use reflection to get the native handle
var ref = new WeakReference (streamHandle);
...
// do the test
Assert.AreEqual (1, CFRetainCount (streamHandle.Handle));
// dispose the watcher and wait for GC to run
Assert.IsNull (ref.Target); |
|
I added test and verified it fails in CI without the fix same way as #40888 I use new trick to push test to the and making sure that it does not run with any other tests. |
|
/azp run |
|
Azure Pipelines successfully started running 4 pipeline(s). |
src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Unix.cs
Outdated
Show resolved
Hide resolved
carlossanlop
left a comment
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.
@wfurt I left a small nit comment.
Also, there were failures in musl and in outerloop. Would you mind taking a look?
|
/azp run |
|
Azure Pipelines successfully started running 4 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 4 pipeline(s). |
|
System.Runtime tests failures are unrelated. They also fail in master. The Musl run did not producer any reasonable output., That seems like infrastructure problem. |
|
Thank you for your contribution. As announced in dotnet/coreclr#27549 this repository will be moving to dotnet/runtime on November 13. If you would like to continue working on this PR after this date, the easiest way to move the change to dotnet/runtime is:
|
carlossanlop
left a comment
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.
Thanks for checking the unit tests. I don't have any more input.
When even stream is created it needs to be properly cleaned up in order to close associated file handles and associated resources.
https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/FSEvents_ProgGuide/UsingtheFSEventsFramework/UsingtheFSEventsFramework.html
We need to call FSEventStreamInvalidate and FSEventStreamRelease. Conveniently, it seems like this is all encapsulated in SafeEventStreamHandle's ReleaseHandle.
I run repro code from #40888 in loop and I did not see any descriptor leak. (The leak was pretty obvious without the fix)
I may spent more time tomorrow thinking if there is some good way how to add test but it may be tricky to verify OS resources.
fixes #40888