This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Repository navigation
close _eventStream when stopping watcher #41013
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c0f2178
close _eventStream when stopping watcher
wfurt 1999648
feedback from review
wfurt 19b0500
pull in ResourceLimits
wfurt 7a8772d
Merge branch 'master' of https://github.com./dotnet/corefx into watch…
wfurt d325a2f
add test for leaking handle
wfurt ecf973b
fix typo
wfurt fd3a50f
force run for finalizers
wfurt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Unix.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Runtime.InteropServices; | ||
| using System.Threading; | ||
| using Microsoft.DotNet.XUnitExtensions; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace System.IO.Tests | ||
| { | ||
| public partial class DangerousFileSystemWatcherTests | ||
| { | ||
| [ConditionalFact] | ||
| [OuterLoop("Slow test with significant resource usage.")] | ||
| public void FileSystemWatcher_Unix_DoesNotLeak() | ||
| { | ||
| Interop.Sys.GetRLimit(Interop.Sys.RlimitResources.RLIMIT_NOFILE, out Interop.Sys.RLimit limits); | ||
| _output.WriteLine("File descriptor limit is {0}", limits.CurrentLimit); | ||
|
|
||
| if (limits.CurrentLimit > 50_000) | ||
| { | ||
| throw new SkipTestException($"File descriptor limit is too high {limits.CurrentLimit}."); | ||
| } | ||
|
|
||
| try { | ||
| for (int i = 0; i < (int)limits.CurrentLimit; i++) | ||
| { | ||
| using (var watcher = new FileSystemWatcher(TestDirectory)) | ||
| { | ||
| watcher.Created += (s, e) => { } ; | ||
| watcher.EnableRaisingEvents = true; | ||
| } | ||
|
|
||
| // On some OSes system resource is released in finalizer. | ||
| GC.Collect(); | ||
| GC.WaitForPendingFinalizers(); | ||
| } | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| // If we use all handles we may not have luck writing out errors. | ||
| // Try our best here. | ||
| Console.WriteLine(e.Message); | ||
| _output.WriteLine(e.Message); | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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
tokenhere? TheRunningInstanceclass received a copy of this token in its constructor, so why not perform these two actions insideCancellationCallbacktoo? (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 = nullshould 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.