parcel-bundler / watcher

👀 A native C++ Node module for querying and subscribing to filesystem events
MIT License
656 stars 45 forks source link

Deadlock between Watcher and Debounce threads (fix #187) #189

Open bpasero opened 3 weeks ago

bpasero commented 3 weeks ago

fix https://github.com/parcel-bundler/watcher/issues/187

There are two threads involved in Watcher.cc and Debounce.cc each calling into respective methods of the other and thus each potentially holding onto locks of the other. This can lead to a deadlock in the following scenario:

While the Debounce.cc thread is processing callbacks in the Debounce::notify() method, it holds its own lock. The method loops over callbacks to process in Watcher.cc which itself requires a lock in Watcher.cc. If an event gets reported while the debouncer is in Watcher.triggerCallbacks(), a deadlock is present, because:

devongovett commented 2 weeks ago

Thanks for the deep investigation here! This looks good to me.