Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible deadlock on closing the watcher on kqueue #230

Merged
merged 4 commits into from
Jan 10, 2018
Merged

Fix possible deadlock on closing the watcher on kqueue #230

merged 4 commits into from
Jan 10, 2018

Conversation

nhooyr
Copy link
Contributor

@nhooyr nhooyr commented Dec 29, 2017

if the watcher is closed from within the goroutine listening on the events or errors channel, then no one will be receiving on the events or errors channel which may lead the readEvents goroutine to block on a send to one of those channels. Then the close call on the watcher will never return because the readEvents goroutine will never receive from the done channel leading the close call to block.

This PR fixes that by using a select statement in readEvents every time it wants to send on a channel to ensure that it will also always return if the watcher is closed without a deadlock.

Thanks to @glycerine for working on this in #188.

This PR closes #188 #187 #145 #211 #225

glycerine and others added 3 commits December 28, 2017 02:26
raw channel work (not inside a select) should
always be prohibited in production code, as
it readily causes deadlocks on shutdown.

Also adds the test TestWatcherClose from #145.
This request duplicates that test, with two
lines fixed to address the houndcli-bot review
concerns.

Fixes #187
Fixes #145
@nhooyr
Copy link
Contributor Author

nhooyr commented Dec 29, 2017

Already filed out the CLA.

Copy link

@zellyn zellyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nathany nathany merged commit 3d33f50 into fsnotify:master Jan 10, 2018
@nhooyr nhooyr deleted the fix187 branch January 10, 2018 04:19
aaronbee pushed a commit to aristanetworks/fsnotify that referenced this pull request Dec 26, 2019
* avoid deadlocks on Close()

raw channel work (not inside a select) should
always be prohibited in production code, as
it readily causes deadlocks on shutdown.

Also adds the test TestWatcherClose from fsnotify#145.
This request duplicates that test, with two
lines fixed to address the houndcli-bot review
concerns.

Fixes fsnotify#187
Fixes fsnotify#145

* cleanup and simpler test

* also fix fsnotify#225

* fix tests

Cherry-pick of
fsnotify@3d33f50
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.

None yet

4 participants