-
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
fs.watch emitting file change when file getting read after some time #50920
Comments
This behavior is truly random and I couldn't understand why... |
I created a new empty folder and created a file and a folder inside of it. I got the following events.
It seems that all the events are correct. In addition, I opened the parent folder using Visual Studio Code and clicked on all the files and folders there. No event was generated. As a result, I was not able to reproduce the issue with the latest versions of Node.js (23.0.0, 22.9.0, 20.18.0, and 18.20.4). Do you think this issue can be closed now? |
@richterdennis can you retry the behavior from @huseyinacacak-janea? |
@RedYetiDev It is still the same behavior like I reported in the beginning. I opened my code folder created an index.mjs like in the original post then exec
Even if I open files in other editors like the windows default text editor and without git involved it fires a change event for this file. I am using node v20.10.0 on Win11 23H2 |
What about 20.18.0? |
I updated my node version real quick and yes it is still the same behavior.
Just by opening the file. Maybe it is relevant: I was not in this folder before or read a file from it. When I reopen the file no event is triggered. |
After further investigation, I discovered that this situation happens when you open a project folder in Visual Studio Code. For example, I added Note that this doesn't happen when you create a new folder and open it in the VS Code. For some reason, the VS Code doesn't change its last access time. It's probably related to the way the VS Code is implemented. Given these findings, this problem is most likely related to the VS Code, not Node.js. |
@huseyinacacak-janea It is not only vs code. It also happens with other editors like the Windows TextEditor. Even the img preview of windows explorer triggering the event. I put the index.mjs in my images folder and just opened a sub folder and get a change event for every image:
To make it clear, I was not browsing in the subfolder before. I checkt the meta information of the files and the last access time was updated. But this should not trigger the change event of node watch imo, because the file it self did not changed |
Do you know if the edited date on the file properties changed? |
The edited date did not changed.
|
Node.js subscribes to the events stated here. node/deps/uv/src/win/fs-event.c Lines 47 to 54 in 7ddd2c2
Could you please check the access times of the files that trigger the change event? |
@huseyinacacak-janea yes the last access time of the files that triggering the event got updated which makes sense because they got accessed. Thank you for sharing the part where the magic happens. I guess removing node/deps/uv/src/win/fs-event.c Line 307 in 7ddd2c2
|
If those dates changed, which they did, this is not an issue that is actionable from Node.js. If anything, it would be an libuv issue. |
You guys know better about what the next steps should be. Unfortunately, |
If you think this is an issue, you should report it to libuv, which handles which events are watched. |
Version
v20.10.0
Platform
Microsoft Windows NT 10.0.22621.0 x64
Subsystem
No response
What steps will reproduce the bug?
Create file index.mjs in a random folder of your system (I am using Win 11) with files in it.
index.mjs content:
Open a console and run
node index.mjs
Then just browse through the folders and files and maybe open files with your IDE.
If I open a file from a random project I get for example:
Just by opening it.
fs.watch is also used in the
node --watch
implementation which is causing multiple reloads just because VS Code is reading some files.How often does it reproduce? Is there a required condition?
The event occurs on the first read and then after some time. I don't know more details.
What is the expected behavior? Why is that the expected behavior?
The expected behavior is not triggering a change event when nothing changed.
What do you see instead?
Getting a change event triggered by opening a file..
Additional information
Sometimes there is also a
The text was updated successfully, but these errors were encountered: