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

Ensure closing watchers does not affect other watchers #1018

Merged

Conversation

timneutkens
Copy link
Contributor

@timneutkens timneutkens commented Jul 12, 2020

If the first watcher that was created gets closed all other watchers will no longer receive events.

Ran into this scenario after we upgraded Next.js to use the latest chokidar that came with the latest stable watchpack. With chokidar v2 (which watchpack previously depended on) this test passes fine. Using v3 it stops reporting filesystem events.

So far I've tracked it down to this particular line:
https://github.com/paulmillr/chokidar/blob/master/lib/fsevents-handler.js#L149

Because the part that creates the context is only called on the first watcher the fsw variable will
always refer to that first watcher.

  • The code in particular loops over the listeners on const.listeners
    • It doesn't need to know if the watcher itself is closed, only if there's listeners left
    • The listeners are correctly removed when a watcher is closed
    • The watcher itself is thrown away correctly when the last listener of that path is deleted
    • Given the above it seems that the best solutions to solve this issue is checking cont.listeners.size instead of fsw.closed
    • Considering the watcher is cleaned up correctly on close the check might not be necessary, though it probably handles an edge case of in-between closing the watcher.

The symptoms (only on macOS) would be that webpack did not recompile after introducing an error or after doing a bunch of quick changes to a certain file. With the change in this PR applied the symptoms are no longer there.

The particular reason this surfaces in webpack is that when an error happens the watchers are closed and recreated when a compilation error happens as files/dependencies could have changed in between.

If the first watcher that was created gets closed all other watchers will no longer receive events.

Ran into this scenario after we upgraded Next.js to use the latest chokidar that came with the latest stable watchpack. With chokidar v2 (which watchpack previously depended on) this test passes fine. Using v3 it stops reporting.
@timneutkens
Copy link
Contributor Author

Ran the changes against the full test suite 322 passing (2m), 3 failing, the 3 failing are unrelated to the changes and happened on my machine with the master branch too 👍

@timneutkens timneutkens changed the title Add failing test case for watcher close affecting other watchers Ensure closing watchers does not affect other watchers Jul 12, 2020
@paulmillr
Copy link
Owner

Thank you!

I’ll be reviewing/merging this in a bit.

@timneutkens
Copy link
Contributor Author

Thanks @paulmillr 🙏

@timneutkens
Copy link
Contributor Author

Hey @paulmillr, just checking in on this as our Next.js test suite fails a few tests related to this issue. Let me know if there's any changes needed 👍 Thanks!

@paulmillr paulmillr merged commit bfcde1c into paulmillr:master Jul 14, 2020
@paulmillr
Copy link
Owner

New release is coming today

@timneutkens timneutkens deleted the add/failing-test-for-closed-watcher branch July 14, 2020 15:40
@timneutkens timneutkens restored the add/failing-test-for-closed-watcher branch July 14, 2020 15:40
@timneutkens timneutkens deleted the add/failing-test-for-closed-watcher branch July 14, 2020 15:40
@timneutkens
Copy link
Contributor Author

timneutkens commented Jul 14, 2020

Awesome! Thanks @paulmillr 🙏

@timneutkens
Copy link
Contributor Author

Apparently github autocompleted to the wrong Paul (Paul Irish) 🤦 Thanks again @paulmillr 🙏

timneutkens added a commit to timneutkens/watchpack that referenced this pull request Jul 23, 2020
Makes sure the version with this patch is installed: paulmillr/chokidar#1018
ycjcl868 added a commit to umijs/umi that referenced this pull request Aug 3, 2020
sorrycc pushed a commit to umijs/umi that referenced this pull request Aug 3, 2020
* chore: upgrade deps

* chore: @hapi/joi

* chore: ref paulmillr/chokidar#1018
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