When using fs.watch() to watch several directories, and changing a file with either fs.writeFileSync or fs.appendFileSync, an unrelated FSWatcher for a similarly named directory is getting an event.
Code at https://github.com/Krinkle/sandbox/blob/node-fs-watch/test.js.
Build output at https://travis-ci.com/Krinkle/sandbox/jobs/167573963.
In brief:
- home/
- a/
- file1
- b/
- file1
- file2
- bb/
- file1
Using fs.watch( .., { encoding: 'utf8', recursive: false }) an FSWatcher is created for home/a, home/b and home/bb.
A modification is made to home/bb/file1.
An event relating to home/bb/file1 (file) and/or home/bb (directory).
Two events:
change home/b/file1change home/bb/file1... modifying home/bb/file1
home/b [change: UNEXPECTED] rename /file1
home/bb [change: expected] rename file1
It is consistently happening in this way on both Travis CI and for myself locally. It has confused me for a quite a while, and I am at a loss as to why this is happening. It seems to specifically result in an event for the same name in a similarly named directory.
It never fires for a or for file2. Rather, bb/file1 always misfires for b/file1.
Any chance you've tried running this on Linux or Windows or anything else on Travis CI or elsewhere? I'm curious if it's macOS-only or not.
Yep, I've got 11 sibling jobs on the same Travis build, for other environments 😃
https://travis-ci.com/Krinkle/sandbox/builds/95971463
os:
- linux
- osx
- windows
node_js:
- 11
- 10
- 8
- 6
The behaviour is the same across Node.js versions.
Linux:
Windows:
macOS:
It appears specific to macOS, and not specific to Travis CI; as I'm seeing the same problem on my workstation (MacBook, Node.js 10 from Homebrew, nonvirtualised).
@nodejs/fs @nodejs/platform-macos
I'm > 50% confident that https://github.com/libuv/libuv/pull/2082 fixes this.
I'm closing this as fixed in libuv 1.25.0. Please reopen if it's not the case.
Most helpful comment
I'm > 50% confident that https://github.com/libuv/libuv/pull/2082 fixes this.