chokidar icon indicating copy to clipboard operation
chokidar copied to clipboard

Fix for a race condition on Linux

Open dividedmind opened this issue 2 years ago • 5 comments

Sometimes, when another process just happened to create a file when we were setting up a watch, the new file wouldn't be noticed.

To prevent the event not being generated in this case, schedule a directory rescan immediately after setting up a watch.

Fixes #1112


Also, another commit here to fix brittle tests. It might be related to #923

dividedmind avatar Jul 08 '22 12:07 dividedmind

good stuff!

paulmillr avatar Jul 08 '22 17:07 paulmillr

Looks like the fix is breaking some tests on non-linux platforms. Do you think it's a good idea to conditionally do this on Linux only? Or do you think the failures are unrelated? I don't have access to either platform so I can't say for sure, but the test suite is quite brittle. The one fix I included here seemed to be enough to get it to pass robustly on my system, but there might be more dragons there.

dividedmind avatar Jul 08 '22 18:07 dividedmind

The nodefs-handler is not used on macos, so i'm not sure how to fix it. Maybe in the same way in fsevents-handler.

paulmillr avatar Jul 08 '22 18:07 paulmillr

That's a good point, I forgot. In this case I think it's fair to say that these test failures must be unrelated.

dividedmind avatar Jul 10 '22 14:07 dividedmind

I changed it to only do the readdir if polling is enabled and added a workaround for a Node 8 bug. I wanted to take a look at more Node 8 test problems, but then I realized it's over two years past EOL and it's probably not worth the trouble. I verified tests pass robustly on Node >= 14 on Linux. The MacOS and Windows test failures seem unrelated, so I think this is good to merge.

dividedmind avatar Jul 10 '22 18:07 dividedmind