-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
watch: fix null fileName
on windows systems
#49891
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is fileName null in this case? if it is do we want to fire #onChange ?
I'm not quite sure what the correct interpretation of null would be and what action to take. |
@nodejs/fs @bnoordhuis do you happen to know? (why/when null can appear as fileName) |
That can happen when the ReadDirectoryChanges IOCP request doesn't complete properly. The NT kernel has this half-way state where the request doesn't fail outright but neither does it produce a valid file change event. Libuv reports it as a UV_CHANGE event with a NULL path because presumably something changed even if we don't know what. I suppose libuv could pass the original path (the path it's been told to watch) although I'm not completely sure that's 100% harmless. |
@@ -98,7 +98,7 @@ class FilesWatcher extends EventEmitter { | |||
} | |||
const watcher = watch(path, { recursive, signal: this.#signal }); | |||
watcher.on('change', (eventType, fileName) => this | |||
.#onChange(recursive ? resolve(path, fileName) : path)); | |||
.#onChange(recursive ? resolve(path, fileName ?? '') : path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment to here referencing/mentioning @bnoordhuis's comments? It's important to not lose any knowledge we have.
Landed in 9db4bf4 |
We shouldn't have merged this while having an open/pending pull request review comment. |
Was it a blocker? We can add the comment now without waiting further. This was open for 3 months. |
PR-URL: #49891 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
PR-URL: #49891 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
PR-URL: #49891 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
This fixes a Node.js crash when running on Windows with
--watch
.The issue is that
fs.watch()
sometimes returnsnull
for thefilename
as described in the official Node.js documentation.The thrown error:
There is also a Stack Overflow question related to this issue.