-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 says every single file in my folder changed, randomly #21643
Comments
Cannot reproduce. Can you provide specific Windows version that you are using? Do you have any AV software running? |
Can you please try creating an entire new project with something like angular generator, then rebooting and using my watch script on that folder, and opening the folder in Windows Explorer? That should trigger it. My Windows version is 10.0.17134.112 and no Antivurs whatsoever |
I still can't reproduce. I've followed this guide, made sample app, rebooted, and started the app (which made your script print quite some "... changed" messages). Accessing the files by opening them in notepad or browsing through the folders in Explorer does not trigger the message. Does this also happen with folders not generated by some app generator? Under the hood, Node just uses ReadDirectoryChangesW with very little extra logic. If those files are getting reported, then something is accessing them somehow. If you feel like it, you can try commenting out some of the "watch options" in https://github.com/nodejs/node/blob/v10.5.0/deps/uv/src/win/fs-event.c#L47-L54, rebuild Node and see if it still reproduces. |
@bzoz thanks for doing such a thorough test. I rebooted in Safe Mode just in case, and the issue still persists. If you can, please try with a moderately big project (at least 5 folders and a 3rd level depth on some of them, with actual files) and open some of them in Windows Explorer while the In my computer, the "change" event triggers with simply opening folders in Windows Explorer, I just checked if any date changed but none of them is current (creation date, last accessed, modification date, and something called just "date"), judging by the enablable columns in detail view. |
@bzoz fyi, i just found a PowerShell script to watch the folder at the same time than the nodejs's ### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\Users\Seb\dev\elder"
$watcher.Filter = "*.*"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
### DEFINE ACTIONS AFTER AN EVENT IS DETECTED
$action = { $path = $Event.SourceEventArgs.FullPath
$changeType = $Event.SourceEventArgs.ChangeType
$logline = "$(Get-Date), $changeType, $path"
Add-content "D:\log.txt" -value $logline
}
### DECIDE WHICH EVENTS SHOULD BE WATCHED
Register-ObjectEvent $watcher "Created" -Action $action
Register-ObjectEvent $watcher "Changed" -Action $action
Register-ObjectEvent $watcher "Deleted" -Action $action
Register-ObjectEvent $watcher "Renamed" -Action $action
while ($true) {sleep 5} This is what each console showed at the exact time when I created the "hola" file and renamed it to "wapa": PowerShell script:
NodeJS
|
Are you 100% sure you do not have any extension (or maybe malware) that accesses this files? Normally, when you write something to a file you get two notifications - one for file content change and one for attributes (mtime) change. You are getting only one, so most likely something is messing with attributes. What we could do is try with Python: in http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html at the very bottom there is |
@bzoz I just checked with that script and it works perfectly fine, here's an screenshot of both scripts workingat the same time, while creating and renaming "hola" to "wapa". As you can see, in Python it works fine as intended, as it also does in PowerShell, but Node's Top window is my NodeJS script, bottom window is the Python script you linked. As I told you, I also tested on Safe Mode so it's not an external problem. PS: I want to add that I browsed the folders with Windows Explorer while running the script,, in order to trigger |
Just a random passerby. In libuv as @bzoz pointed out there is this, which notes that libuv listens to
But indeed it would probably it be better if there was 2 events for change (contents and timestamp), though based on win api docs there is no way to differentiate those, so maybe ability to specify what to watch for (this may only me a intersection of supported features across the OSs, but it shouldn't be that hard to implement, though I'm not familiar with libuv codebase so I cannot be sure)? |
Thanks, @lundibundi, that fixed the problem for good. ❤
|
For the record, this is affecting me on Windows (in the Linux subsystem), and the disablelastaccess change isn't helping. I'm going to try with the native Windows node, but it's a little tricky to do so. I don't really see why node is monitoring for accessed files at all, particularly when that is not the behaviour on Linux. |
10.5
Windows 10
I have a development environment in which I use browserSync and Nodemon to accomplish automatic reloading of my client and server respetively. I recently migrated from macOS to Windows, and my setup worked fine in macOS, but now the pages reload randomly when I click something or just open the folder in Explorer.
I decided to dig a little deeper and make a separate script to watch the 'change' event and see what happens. To my surprise, it gets triggered with anything!. I'm guess it's something to do with Windows marking files as "last accessed" or something like that, but the contents aren't changing so this shouldn't happen!
Here's my script:
Here's a sample output:
The text was updated successfully, but these errors were encountered: