Skip to content

Fix intermittent hangs in FsEventWatcher - #1013

Open
dileping wants to merge 3 commits into
notify-rs:mainfrom
renewedvision:cfrunloop-race-fix
Open

dileping wants to merge 3 commits into
notify-rs:mainfrom
renewedvision:cfrunloop-race-fix

Conversation

@dileping

Copy link
Copy Markdown

Description

In some situations, such as rapid watch/unwatch cycles, FsEventWatcher can intermittently hang due to a race condition involving CFRunLoop. This PR adds an extra layer of safety: CFRunLoop runs in a loop with a 0.5-second timeout per iteration. The stop_flag_thread flag is checked on every iteration, thus eliminating this hang.

The race condition can occur when CFRunLoopStop is called in the gap between checking stop_flag_thread and CFRunLoopRun actually starting the loop internally.

Related Issues

Related to #118 and #208. This addresses the stop-before-run race described in #118.

justintyre and others added 3 commits September 29, 2026 16:35
stop() sets the stop flag and calls CFRunLoopStop, then joins the runloop thread. If that happens after the thread has checked the flag but before CFRunLoopRun starts, the stop is discarded and the join blocks forever. Run the loop with a bounded timeout and re-check the flag after each return. The workspace also resolves notify-types from crates.io so this fork shares event types with published consumers.

(cherry picked from commit 9a8265f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants