Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e5e6261

Browse files
committed
Merge pull request #2786 from stephentoub/fix_fsw_regression
Fix regression in FileSystemWatcher
2 parents 6270b91 + 6568da5 commit e5e6261

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Win32.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ private void StopRaisingEvents()
7575
// This operation doesn't need to be atomic because the API will deal with a closed
7676
// handle appropriately. If we get here while asynchronously waiting on a change notification,
7777
// closing the directory handle should cause ReadDirectoryChangesCallback be be called,
78-
// cleaning up the operation.
78+
// cleaning up the operation. Note that it's critical to also null out the handle. If the
79+
// handle is currently in use in a P/Invoke, it will have its reference count temporarily
80+
// increased, such that the disposal operation won't take effect and close the handle
81+
// until that P/Invoke returns; if during that time the FSW is restarted, the IsHandleInvalid
82+
// check will see a valid handle, unless we also null it out.
7983
_directoryHandle.Dispose();
84+
_directoryHandle = null;
8085

8186
// Set enabled to false
8287
_enabled = false;

src/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Changed.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ public static void FileSystemWatcher_Changed_FileDataChange()
146146
}
147147
}
148148

149-
[ActiveIssue(2740)]
150149
[Theory]
151150
[InlineData(true)]
152151
[InlineData(false)]

0 commit comments

Comments
 (0)