Skip to content

Loading…

Windows: 0.8.0 emitting too many events #104

Closed
scien opened this Issue · 7 comments

6 participants

@scien
chokidar = require 'chokidar'
watcher = chokidar.watch 'my_directory', {
  ignored: /(^\.|\.swp$|\.tmp$|~$)/
}
watcher.on 'change', (filepath) ->
  console.log filepath

0.7.1 works as expected. 0.8.0 causes the above code to report the same file being updated multiple times when saving just once. The number of emitted events seems to continue to grow (but not predictably) with more saves. First time it might emit twice, then three times, then six times.

adding @gtek1000 who ran into the issue and may be able to help debug/test a patch.

@LiamKarlMitchell

Also happning on Windows 7 for me.

When I start up I get

Directory ./test has been added
File test\a.js has been added
Directory test\childDirectory has been added
File test\b.js has been added
File test\childDirectory\woo.js has been added

Which is expected.

And then when I save a.js using notepad.

File test\a.js has been changed
File test\a.js has been changed
File test\a.js has been added
File test\b.js has been added
Directory test\childDirectory has been added
File test\a.js has been added
File test\b.js has been added
Directory test\childDirectory has been added

Which is bad. I wonder if its created two watches or if event is triggered twice?.

Test code.

var b = chokidar.watch('./test', { persistent: true })
  .on('add', function(location) {console.log('File', location, 'has been added');})
  .on('addDir', function(location) {console.log('Directory', location, 'has been added');})
  .on('change', function(location) {console.log('File', location, 'has been changed');})
  .on('unlink', function(location) {console.log('File', location, 'has been removed');})
  .on('unlinkDir', function(location) {console.log('Directory', location, 'has been removed');})
  .on('error', function(error) {console.error('Error happened', error);})

Expected: the file b.js and other directory should not be added again.
It seems like its rewalking the directory? Kind of making this unusable.

#110
Where I think I have found the cause of the issue.

@daywiss

I am running into the same problem in Windows 7. I think it is also sporadically crashing, but I need more time to confirm.

@SunboX

Same on Windows 8.1 ... one file changed fires three change events

@tym-network

You can take a look at that pull request: #124

The problem came from paths that were not identical, this commit fixed it:
tym-network@6afeab3

@LiamKarlMitchell

Hmm Thanks @tym-network I will take a look sometime soon.
If this fixes the problem then I can finally use this yay.

@tym-network

After some tests, I don't see how I could solve the problem when "usePolling" is set to false (on Windows 7).
I try to watch a directory containing some files and another directory.
I added a console.log(event, path); in the callback of _watch fs.watch(...).
This is what I got:
When adding a file
"rename myFile.js"
"change myFile.js"
"change myFile.js"

When renaming a file
"rename null"
"rename myFile.js"
"change myFile.js"

When deleting a file
"rename null"

Because I'm using SublimeText, changing the content of a file was a real mess (because of the temporary files).

The thing that I don't really understand in the code is why do we watch the directory itself, but also every file in it with read? When you run fs.watch on a folder, all the files inside are automatically watch. I commented the calls to read() in _handleDir and _watch fired the events on the files contained in the directory. Considering the fact that the number of "watch" instances is limited (128 in Linux by default, I don't know about Windows' limitations), wouldn't it be clever to watch only the directory and let the OS handle the events of all the files inside?

Anyway, if the problem is fs.watch itself, we won't be able to fix this in chokidar directly...

If someone could also run some tests to see if fs.watch fires the same events, it would be great.

This was referenced
@es128
Collaborator

Please start new issues, preferably with demonstration code, if any of these problems are still observed against master branch.

@es128 es128 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.