Skip to content

FileSystemWatcher SymbolicLink tests failing after inotify refactor (#117148) #125737

Closed

Description

@lewing

Summary

Multiple FileSystemWatcher SymbolicLink tests have started failing on Linux since the inotify refactor in #117148 (merged Jan 26, 2026). The failures appear as missed Created events with the message "Created event did not occur as expected".

Suspected Root Cause

PR #117148 refactored the Linux FileSystemWatcher to use a single shared inotify instance. There appears to be a race condition in Watcher.Start() (FileSystemWatcher.Linux.cs) where Start() returns before the ProcessEvents background thread is guaranteed to be reading from the inotify file descriptor:

StartThread()           // spawn background thread
CreateRootWatch()       // register inotify watch with kernel
_inotify.AddWatcher()   // register with shared instance
DequeueEvents()         // async fire-and-forget
_emitEvents = true
// Start() returns — but ProcessEvents may not be reading yet

If a filesystem event occurs in this gap (between Start() returning and ProcessEvents entering its read() loop), the event can be missed or delayed past the test timeout.

Affected Tests

The _IncludeSubdirectories variant fails more consistently because it requires multiple watch registrations, widening the race window.

Timeline

Environment

Failures observed on:

  • Linux ARM32 (Debian 13 on AzureLinux 3 Arm64 cross-arch) under jitstress
  • Multiple Linux x64 configurations (crossgen2, libraries-jitstress)

JitStress and slower hardware (arm32) widen the race window, making failures more frequent.

Related Issues

Possible Fix

Add a synchronization point in Watcher.Start() that ensures the ProcessEvents thread is blocked on read() before Start() returns — for example a ManualResetEventSlim signaled by the processing thread once it enters the read loop.

/cc @tmds @adamsitnik @jozkee

Activity

  1. added
    untriaged
    on Mar 18, 2026
  2. dotnet-policy-service commented on Mar 18, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-io
    See info in area-owners.md if you want to be subscribed.

  3. added 5 commits that reference this issue on Mar 18, 2026
    47a5000
    a5bf384
    c28805a
    8032b17
    009d8f2
  4. lewing commented on Mar 18, 2026

    @lewing
    MemberAuthor

    we're trying bumping the timeout since the kernel should be handling the buffering #125744

  5. VincentBu commented on Mar 19, 2026

    @VincentBu
    Contributor

    Failed in: runtime-coreclr libraries-jitstress 20260318.1

    Failed tests:

    net11.0-linux-Release-x64-jitstress1_tiered-AzureLinux.3.Amd64.Open
    - System.IO.Tests.Directory_Create_Tests.FileSystemWatcher_Directory_Create_InNestedDirectory
    
    

    Error message:

    Created event did not occur as expected
    

    Stack trace:

       at System.IO.Tests.FileSystemWatcherTest.ExecuteAndVerifyEvents(FileSystemWatcher watcher, WatcherChangeTypes expectedEvents, Action action, Boolean assertExpected, String[] expectedPaths, Int32 timeout) in /_/src/libraries/System.IO.FileSystem.Watcher/tests/Utility/FileSystemWatcherTest.cs:line 328
       at System.IO.Tests.FileSystemWatcherTest.ExpectEvent(FileSystemWatcher watcher, WatcherChangeTypes expectedEvents, Action action, Action cleanup, String[] expectedPaths, Int32 attempts, Int32 timeout) in /_/src/libraries/System.IO.FileSystem.Watcher/tests/Utility/FileSystemWatcherTest.cs:line 198
       at System.IO.Tests.FileSystemWatcherTest.ExpectEvent(FileSystemWatcher watcher, WatcherChangeTypes expectedEvents, Action action, Action cleanup, String expectedPath, Int32 attempts, Int32 timeout) in /_/src/libraries/System.IO.FileSystem.Watcher/tests/Utility/FileSystemWatcherTest.cs:line 168
       at System.IO.Tests.Directory_Create_Tests.FileSystemWatcher_Directory_Create_InNestedDirectory() in /_/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Directory.Create.cs:line 62
       at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
       at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
       at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args) in /_/src/coreclr/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.CoreCLR.cs:line 36
       at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs:line 57
    
  6. added
    blocking-clean-ci-optional
    on Mar 19, 2026
  7. removed
    untriaged
    on Mar 19, 2026
  8. locked and limited conversation to collaborators on Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions