Repository navigation
fs: keep watching directories recreated under a recursive watch - #67747
Open
yohannesjoya wants to merge 1 commit into
Open
yohannesjoya wants to merge 1 commit into
yohannesjoya wants to merge 1 commit into
Conversation
On Linux, recursive fs.watch() keeps one inotify watcher per directory. When a directory below the root was removed and created again before its events were handled, the parent's event found a directory at the same path, and the old watcher, which no longer reports anything, was kept. Changes inside the new directory were then never reported, which also stopped `node --watch-path` from restarting. Handle the event the old watcher emits about the directory itself: if the path now holds a different directory, or nothing, drop the old watcher and start over with what is there. Inotify reports metadata changes to the directory in the same way, and the new directory often reuses the inode number, so directories are compared by inode number and birth time. Fixes: nodejs#67592 Signed-off-by: Yohannes Desta <yohannesdestagebru10@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Linux, recursive
fs.watch()keeps one inotify watcher per directory. When a directory below the root is removed and created again before its events are handled (for examplermSync(dir, { recursive: true })followed bymkdirSync(dir)in a code generator), the parent's event finds a directory at the same path and the old watcher is kept, but it watches the removed directory and reports nothing more. Changes in the new directory are never reported, sonode --watch-pathstops restarting.This handles the event the old watcher emits about the directory itself: if the path now holds a different directory, or nothing, the stale watcher is dropped and the current entry is added again (emitting
renamefor it and its contents). Inotify reports achmodof the directory the same way, and the new directory often gets the same inode number (it did every time on ext4 here), so directories are compared by inode number and birth time. That costs onelstat()per watched directory below the root, on Linux only.Fixes: #67592
The new test fails (hangs) on main and passes with this change.
tools/test.pyforparallel/test-fs-watch*,parallel/test-watch*,sequential/test-*watch*andparallel/test-vfs-watch*passes locally (3 repeats), as doesmake lint-jsfor the changed files. I also ran the reproduction from the issue with--watch-path: it now restarts on every regeneration.AI disclosure: I used an AI assistant to help find the cause and write the test. I reviewed the change and ran the tests above myself.