paulmillr / chokidar

Minimal and efficient cross-platform file watching library
https://paulmillr.com
MIT License
10.8k stars 574 forks source link

Change event is not emitted on Windows when continuously appending to an initially existing file #1297

Closed bersbersbers closed 2 months ago

bersbersbers commented 7 months ago

I see the same thing as #999 on Windows. Essentially, I get only one or two (initial/final) change events for a file despite continuously appending to it. I see the same kind of issues in real life, e.g., VS Code auto-updates of output from https://github.com/pkolaczk/fclones on Windows are stalled until re-focusing VS Code (compare https://github.com/microsoft/vscode/issues/93277).

To reproduce, I used the same code for index.js as https://github.com/paulmillr/chokidar/issues/999#issue-592779484, and

Continuously append to an existing file

echo 1 > output.log
ping -n 2 0.0.0.0
(for /l %f in () do @echo 1) >> output.log

(Without the ping, which emulates a sleep on Windows, it works sometimes, and sometimes not.)

Interestingly, the problem is resolved by Ctrl-C'ing node and restarting the above index.js - so events seem to be generated, but chokidar seems to choke on them somehow.

Also, the issue does not reproduce with either of the following variants:

Continuously append to an initially missing file (hence creating it first)

if exist output.log del output.log
(for /l %f in () do @echo 1) >> output.log

Continuously write to a new file

(for /l %f in () do @echo 1) > output.log

Create a new file in each loop iteration

for /l %f in () do @echo 1 > output.log

Append to a file in each loop iteration

for /l %f in () do @echo 1 >> output.log

chokidar@3.5.3, node v20.8.0, Windows 10 22H2, cmd.exe

bersbersbers commented 7 months ago

Two more notes:

the problem is resolved by Ctrl-C'ing node ...

This is not supposed to mean that chokidar is hanging. It is processing subsequent events just fine if not terminated.

Matsuuu commented 7 months ago

I experienced something similiar. I've got a dockerized environment running on windows, that uses chokidar to watch for file changes. The events don't trigger on the dockerized environment, causing updates not to flow through.

Using usePolling: true helped for me though