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

Only first change event detected when multiple watchers add same file #1240

Closed
zqianem opened this issue Aug 16, 2022 · 2 comments
Closed

Only first change event detected when multiple watchers add same file #1240

zqianem opened this issue Aug 16, 2022 · 2 comments

Comments

@zqianem
Copy link
Contributor

zqianem commented Aug 16, 2022

Describe the bug

If there are multiple instances of a Chokidar watcher watching the same file, only the first change to a file is detected.

Versions:

  • Chokidar version [3.5.3]
  • Node version [v16.16.0]
  • OS version: [Arch Linux x86_64 Kernel 5.18.16-arch1-1]

To Reproduce:

Edit: could not reproduce on Windows 11

On a non-memory filesystem (i.e. not /tmp), run node main.mjs and create/edit hello.txt in the same directory.

// main.mjs
import chokidar from 'chokidar'

let w1 = chokidar
  .watch([])
  .on('all', (event, path) => console.log('w1', { event, path }))

let w2 = chokidar
  .watch([])
  .on('all', (event, path) => console.log('w2', { event, path }))

// if either of the following lines are commented out, change events continue to fire as expected
w1.add('hello.txt')
w2.add('hello.txt')

This outputs:

w1 { event: 'add', path: 'hello.txt' }
w2 { event: 'add', path: 'hello.txt' }
w1 { event: 'change', path: 'hello.txt' }
w2 { event: 'change', path: 'hello.txt' }
# further edits to hello.txt do not cause additional change events

Oddly, there was one time in my testing where the change events did continue to fire with the above setup after I added node main.mjs to package.json's scripts field, but I could not reproduce it again.

Expected behavior

When hello.txt is edited multiple times, change events continue to fire:

w1 { event: 'add', path: 'hello.txt' }
w2 { event: 'add', path: 'hello.txt' }
w1 { event: 'change', path: 'hello.txt' }
w2 { event: 'change', path: 'hello.txt' }
w1 { event: 'change', path: 'hello.txt' }
w2 { event: 'change', path: 'hello.txt' }
w1 { event: 'change', path: 'hello.txt' }
w2 { event: 'change', path: 'hello.txt' }
# etc

Additional context

Likely the cause of rollup/rollup#4508, as Rollup ends up having multiple watchers for files added by plugins via addWatchFile.

@gajus
Copy link

gajus commented Mar 20, 2023

@paulmillr Any pointers of what could be happening here?

Happy to help debug and submit PR if releasing this can get prioritized.

gajus added a commit to gajus/turbowatch that referenced this issue Mar 20, 2023
Turbowatch uses [`fs.watch`](https://nodejs.org/api/fs.html#fswatchfilename-options-listener), which is known to have platform-specific caveats. Unfortunately, Watchman cannot be used due to it not supporting symbolic links (issue [#105](facebook/watchman#105 (comment))) and Chokidar cannot be used due to it failing to detect file changes (issue [#1240](paulmillr/chokidar#1240)). This is not an issue if you are using MacOS, though it may have undersirable side-effects on other platforms. Please raise an issue if you discover a platform-specific issue.
BREAKING CHANGE: Potentially breaking changes for non-MacOS platforms.
@zqianem
Copy link
Contributor Author

zqianem commented Nov 2, 2024

Tested this and seems to be fixed as of v4.01 🎉

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

No branches or pull requests

3 participants