You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a basic race condition when setting up a watch on a directory, in nodefs-handler.js: First the directory contents are scanned, and then a fs.watch watcher is set up. Any file created between those two operations won't be seen, until there's another operation that causes the fs.watch to trigger and the directory is re-scanned.
Versions (please complete the following information):
3.5.1
10.21.0
Linux
To Reproduce:
First add this delay, which doesn't cause the race, just makes it a lot easier to trigger.
--- a/lib/nodefs-handler.js+++ b/lib/nodefs-handler.js@@ -556,6 +556,9 @@ async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
if (this.fsw.closed) return;
}
+ console.error("race!");+ await new Promise(res => setTimeout(res, 5000));+
closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
// if current directory is removed, do nothing
if (stats && stats.mtimeMs === 0) return;
Huh, I just spent a couple of hours tracking down the same exact issue. Serves me right for not searching first :)
I think I have a fix, a test case is more difficult however due to this being a race. The only sure way to cause the problem is to add that timeout in chokidar code.
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.
Fixespaulmillr#1112
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.
Fixespaulmillr#1112
Describe the bug
There is a basic race condition when setting up a watch on a directory, in
nodefs-handler.js
: First the directory contents are scanned, and then afs.watch
watcher is set up. Any file created between those two operations won't be seen, until there's another operation that causes thefs.watch
to trigger and the directory is re-scanned.Versions (please complete the following information):
To Reproduce:
First add this delay, which doesn't cause the race, just makes it a lot easier to trigger.
Then use something like this
Actual output
Events for adding files 1 and 2 don't happen until file 3 is created much later:
Expected output
Events for adding files 1 and 2 should happen right before or after
ready
:The text was updated successfully, but these errors were encountered: