Skip to content

Could not find a part of the path in System.IO.Tests.FileSystemWatcherTests.FileSystemWatcher_Directory_Delete_MultipleFilters #98193

Closed

Description

@carlossanlop

Error Blob

{
  "ErrorMessage": "at System.IO.Tests.FileSystemWatcherTests.FileSystemWatcher_Directory_Delete_MultipleFilters",
  "BuildRetry": true,
  "ErrorPattern": "",
  "ExcludeConsoleLog": false
}

Reproduction Steps

===========================================================================================================

C:\h\w\C0550A4F\w\A85A0959\e>"C:\h\w\C0550A4F\p\dotnet.exe" exec --runtimeconfig System.IO.FileSystem.Watcher.Tests.runtimeconfig.json --depsfile System.IO.FileSystem.Watcher.Tests.deps.json xunit.console.dll System.IO.FileSystem.Watcher.Tests.dll -xml testResults.xml -nologo -nocolor -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing  
  Discovering: System.IO.FileSystem.Watcher.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.IO.FileSystem.Watcher.Tests (found 174 of 209 test cases)
  Starting:    System.IO.FileSystem.Watcher.Tests (parallel test collections = on, max threads = 4)
    System.IO.Tests.FileSystemWatcherTests.FileSystemWatcher_Directory_Delete_MultipleFilters [FAIL]
      System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\h\w\C0550A4F\t\#FileSystemWatcherTests_eq2ujqlt.lfo\FileSystemWatcher_Directory_Delete_MultipleFilters_1009_7eam6lig\FileSystemWatcher_Directory_Delete_MultipleFilters_1010_cn2nu7w1'.
      Stack Trace:
        /_/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.cs(436,0): at System.IO.FileSystem.RemoveDirectoryInternal(String fullPath, Boolean topLevel, Boolean allowDirectoryNotEmpty)
        /_/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.cs(261,0): at System.IO.FileSystem.RemoveDirectory(String fullPath, Boolean recursive)
        /_/src/libraries/System.Private.CoreLib/src/System/IO/DirectoryInfo.cs(212,0): at System.IO.DirectoryInfo.Delete(Boolean recursive)
        /_/src/libraries/System.Private.CoreLib/src/System/IO/DirectoryInfo.cs(208,0): at System.IO.DirectoryInfo.Delete()
        /_/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs(1019,0): at System.IO.Tests.FileSystemWatcherTests.<>c__DisplayClass61_0.<FileSystemWatcher_Directory_Delete_MultipleFilters>b__0()
        /_/src/libraries/System.IO.FileSystem.Watcher/tests/Utility/FileSystemWatcherTest.cs(309,0): at System.IO.Tests.FileSystemWatcherTest.ExecuteAndVerifyEvents(FileSystemWatcher watcher, WatcherChangeTypes expectedEvents, Action action, Boolean assertExpected, String[] expectedPaths, Int32 timeout)
        /_/src/libraries/System.IO.FileSystem.Watcher/tests/Utility/FileSystemWatcherTest.cs(198,0): at System.IO.Tests.FileSystemWatcherTest.ExpectEvent(FileSystemWatcher watcher, WatcherChangeTypes expectedEvents, Action action, Action cleanup, String[] expectedPaths, Int32 attempts, Int32 timeout)
        /_/src/libraries/System.IO.FileSystem.Watcher/tests/Utility/FileSystemWatcherTest.cs(168,0): at System.IO.Tests.FileSystemWatcherTest.ExpectEvent(FileSystemWatcher watcher, WatcherChangeTypes expectedEvents, Action action, Action cleanup, String expectedPath, Int32 attempts, Int32 timeout)
        /_/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs(1019,0): at System.IO.Tests.FileSystemWatcherTests.FileSystemWatcher_Directory_Delete_MultipleFilters()
           at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
        /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInvoker.cs(81,0): at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
  Finished:    System.IO.FileSystem.Watcher.Tests
=== TEST EXECUTION SUMMARY ===
   System.IO.FileSystem.Watcher.Tests  Total: 327, Errors: 0, Failed: 1, Skipped: 0, Time: 10.115s
----- end Fri 02/02/2024 18:18:47.75 ----- exit code 1 ----------------------------------------------------------

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=551129
Error message validated: [at System.IO.Tests.FileSystemWatcherTests.FileSystemWatcher_Directory_Delete_MultipleFilters]
Result validation: ✅ Known issue matched with the provided build.
Validation performed at: 2/8/2024 11:20:36 PM UTC

Report

Build Definition Test Pull Request
1342616 dotnet/runtime System.IO.FileSystem.Watcher.Tests.WorkItemExecution #125766

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
0 1 1

Activity

  1. added
    blocking-clean-ci
    runtime-coreclr
    Known Build Error
    on Feb 8, 2024
  2. ghost added
    untriaged
    on Feb 8, 2024
  3. carlossanlop commented on Feb 8, 2024

    @carlossanlop
    ContributorAuthor

    The path has # characters. Are those allowed? Could that be the issue, @dotnet/area-system-io ?

    C:\h\w\C0550A4F\t\#FileSystemWatcherTests_eq2ujqlt.lfo\FileSystemWatcher_Directory_Delete_MultipleFilters_1009_7eam6lig\FileSystemWatcher_Directory_Delete_MultipleFilters_1010_cn2nu7w1

  4. removed
    blocking-clean-ci
    on Feb 15, 2024
  5. jozkee commented on Jun 25, 2024

    @jozkee
    Member

    Looks like we fixed it in 8.0 #79901. Can we backport that test fix?

  6. removed
    untriaged
    on Jun 25, 2024
  7. added this to the Future milestone on Jun 25, 2024
  8. changed the title [-][7.0] Could not find a part of the path in System.IO.Tests.FileSystemWatcherTests.FileSystemWatcher_Directory_Delete_MultipleFilters[/-] [+]Could not find a part of the path in System.IO.Tests.FileSystemWatcherTests.FileSystemWatcher_Directory_Delete_MultipleFilters[/+] on Mar 22, 2026
  9. danmoseley commented on Mar 22, 2026

    @danmoseley
    Contributor

    Note

    This analysis was generated by Copilot.

    PR #79901 fixed the most common failure mode (adding cleanup lambdas to recreate directories between retries), but the test still hits occasionally — the Known Build Error report shows 1 hit in the past month. Two remaining issues likely explain the continued flakiness:

    1. Windows pending-delete race (still causes DirectoryNotFoundException)

    On NTFS, RemoveDirectory marks a directory for deletion but doesn't fully remove it until all handles are closed. The cleanup sequence can race:

    directoryOne.Delete()      → OS marks "pending delete"
      (FSW misses event, timeout)
    directoryOne.Create()      → CreateDirectoryW sees path still "exists" → no-op
      (pending delete completes → directory is now gone)
    directoryOne.Delete()      → DirectoryNotFoundException 💥
    

    AV/indexers or buffered I/O could hold transient handles on the child directory, extending the pending-delete window. The cleanup's Create() silently does nothing because Windows reports the path as still existing.

    Potential fix — wait for the delete to fully complete before recreating:

    cleanup: () => {
        SpinWait.SpinUntil(() => !Directory.Exists(directoryOne.FullName), 2000);
        directoryOne.Create();
    }

    2. EnableRaisingEvents → action() race (causes event to be missed, triggering retries)

    In ExecuteAndVerifyEvents:

    watcher.EnableRaisingEvents = true;
    action();  // Delete fires immediately — zero gap

    EnableRaisingEvents calls ReadDirectoryChangesW asynchronously. If the kernel hasn't finished setting up the watch before Delete() completes, the event is silently dropped. With only 3 attempts × 1s timeout, a loaded CI machine can miss all of them — which then triggers the pending-delete race in issue 1.

    Additionally, RecreateWatcher never disposes the old watcher, so on retries multiple watchers hold handles on the same directory, increasing handle contention and extending pending-delete windows.

    Summary

    Issue 2 explains why events get missed (triggering retries), and issue 1 explains why retries then fail with DirectoryNotFoundException. A robust fix likely needs both — wait for real deletion before Create(), and give the watcher time to register before acting.

  10. added
    in-pr
    on Mar 22, 2026
  11. added a commit that references this issue on Apr 2, 2026
    c740399
  12. added a commit that references this issue on Apr 9, 2026
    3a94711
  13. locked and limited conversation to collaborators on May 3, 2026
  14. added a commit that references this issue on Jul 15, 2026
    6ce4321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Known Build Errorarch-x86area-System.IOin-pros-windowsruntime-coreclr

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions