-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
[20.14.0][fs] recursive watch on Linux crashes on .close()
#53350
Comments
I am on macOS aarch 64 with node Also I added |
The |
edit: I didn't change the file name in the bash one liner script to |
Not sure where the indx.mjs came from. file has to be named watch.mjs for the steps to work. above will initialize a git repo in the current directory and remove it right away 100 times. make sure you do it all in a new empty directory. |
Sorry for the confusion, I renamed I tested I tested on version node Will see what other people reproduce on this one. |
I believe It has to be Linux to be using the internal recursive_watch.js (and see the issue) |
Here is a fix: #53452 |
Version
20.14.0
Platform
Linux fedora 6.8.11-300.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Mon May 27 14:53:33 UTC 2024 x86_64 GNU/Linux
Subsystem
internal/fs/recursive_watch
What steps will reproduce the bug?
watch.mjs
:git init
in foldernode watch.mjs
the above command stages and unstages
watch.mjs
100 times. you should see watch errorsand
This is because git saves the lock, and removes it immediately.
Sometimes this
statSync
call fails (recursive_watch:152):which could have been avoided by using
throwIfNoEntry: false
and checking the return value.the real race happens when the above
statSync
call succeeds, and then thewatch()
call (two lines down) fails because the file just got deleted. This can be seen in the second stack trace above. In this scenario,this.#files
will be populated with the stats object, butthis.#watchers
won't have a matching watcher registered in the map.When calling
close()
on watcher after the second scenario happened, the following loop in close will fail:as
this.#watchers.get(file).close();
will fail when trying to callclose()
on undefined (watch()
call blew up, so nothing inthis.#watchers
forfile
).the error looks like:
How often does it reproduce? Is there a required condition?
Pretty consistently.
What is the expected behavior? Why is that the expected behavior?
Don't crash on
close()
.When querying whether a node exists or not (
statSync
), usethrowIfNoEntry
to avoid generated errors.What do you see instead?
calling
close()
crashes the processAdditional information
@mcollina you might be interested. looks like your cup of tea.
The text was updated successfully, but these errors were encountered: