Description
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
SymbolicLink_Changed_Tests.FileSystemWatcher_SymbolicLink_TargetsDirectory_Create— failing on linux arm32 jitstress (System.IO.Tests.Directory_Create_Tests.FileSystemWatcher_Directory_Create_InNestedDirectory fails with "Created event did not occur as expected" #103630 false match)SymbolicLink_Changed_Tests.FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories— consistently failing, disabled in Disable FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories #124849
The _IncludeSubdirectories variant fails more consistently because it requires multiple watch registrations, widening the race window.
Timeline
- Jan 26: PR FileSystemWatcher.Linux: use a single inotify instance and refactor watch tracking. #117148 merged (inotify refactor)
- Feb 20: FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories failed with missed event #124677 filed —
_IncludeSubdirectoriesvariant failing - Feb 25: FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories failing on multiple OSes #124847 / Disable FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories #124849 — test disabled
- Mar 17: Non-
_IncludeSubdirectoriesvariant appearing in CI, incorrectly attributed to System.IO.Tests.Directory_Create_Tests.FileSystemWatcher_Directory_Create_InNestedDirectory fails with "Created event did not occur as expected" #103630 via overly broad error pattern match
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
- FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories failed with missed event #124677 —
_IncludeSubdirectoriesKnown Build Error (27 hits in first month) - FileSystemWatcher_SymbolicLink_TargetsDirectory_Create_IncludeSubdirectories failing on multiple OSes #124847 — same, disabled-test tracking
- System.IO.Tests.Directory_Create_Tests.FileSystemWatcher_Directory_Create_InNestedDirectory fails with "Created event did not occur as expected" #103630 — old Windows FSW flakiness, now falsely matching this Linux failure due to broad error pattern
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
dotnet-policy-service commentedon Mar 18, 2026
Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.
Fix FileSystemWatcher startup race on Linux
Fix FileSystemWatcher startup race on Linux
Fix FileSystemWatcher startup race on Linux
Increase FileSystemWatcher test event timeout to 1000ms
Increase FileSystemWatcher test event timeout to 1000ms
lewing commentedon Mar 18, 2026
we're trying bumping the timeout since the kernel should be handling the buffering #125744
Increase FileSystemWatcher test event timeout to 1000ms (#125744)
VincentBu commentedon Mar 19, 2026
Failed in: runtime-coreclr libraries-jitstress 20260318.1
Failed tests:
Error message:
Stack trace:
Fix FileSystemWatcher test flakiness on Windows and re-enable 86 disa…