windows: lock watch field updates against concurrent WatchList#749
Merged
Merged
Conversation
…ify#709) WatchList() iterates watchEntry.names and reads watchEntry.mask under w.mu, but the I/O thread (addWatch/remWatch/deleteWatch and the rename and remove paths in readEvents) mutated those same fields without the lock. The race detector flagged the mask field; the names map mutation is the more dangerous case since concurrent map write + iterate panics at runtime. Hold w.mu around all writes to mask/names. deleteWatch snapshots the map and mask under the lock and sends events outside it to avoid blocking on the user-facing Events channel while holding the mutex. Regression from v1.9.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #709. Calling
WatchList()concurrently withAdd()/Remove()on Windows raced with the I/O thread mutatingwatchEntry.maskandwatchEntry.namesoutside the lock; the race detector caught themaskaccess but the more dangerous case is concurrent map iteration vs. write onwatchEntry.names, which can panic at runtime. Holdw.muaround all writes to those fields (addWatch,remWatch,deleteWatch, and the rename/remove paths inreadEvents).deleteWatchsnapshots the map and mask under the lock and then callssendEventoutside it to avoid blocking on the Events channel while holding the mutex. AddsTestWatchListRaceas a regression test.