Skip to content
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

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

Open
bersbersbers opened this issue Jan 23, 2024 · 4 comments

Comments

@bersbersbers
Copy link

Originally posted in microsoft/vscode#202446

Steps to Reproduce:

In the VS Code Terminal

  1. echo 1 > output.log (and wait >1s)
  2. code output.log
  3. (for /l %f in () do @echo 1) >> output.log

File does not auto-reload until editor is re-focused.

This is similar to microsoft/vscode#93277, and I observe similar behavior in paulmillr/chokidar#1297.

I rarely use node, so I did not test reproduction using this code. However, bpasero wrote in microsoft/vscode#202446 (comment):

I am able to reproduce with the file watching library already, so please report this over at https://github.com/parcel-bundler/watcher

This is what I am doing here.

@bersbersbers
Copy link
Author

I have reproduction steps, finally.

watcher.bat

@echo off
pushd "%~dp0"
set PATH=%PATH%;C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VisualStudio\NodeJs

echo. > watcher.log

call npm i @parcel/watcher
start cmd /k node watcher.js

(for /l %%f in () do @echo %time%) >> watcher.log

@REM (for /l %%f in () do @echo %time% && timeout /t 1) >> watcher.log
@REM for /l %%f in () do (@echo %time% >> watcher.log)
@REM for /l %%f in () do ((@echo %time% >> watcher.log) && @echo %time%)
@REM for /l %%f in () do ((@echo %time% >> watcher.log) && @echo %time% && timeout /t 0)
@REM for /l %%f in () do ((@echo %time% >> watcher.log) && @echo %time% && timeout /t 1)

watcher.js

const watcher = require('@parcel/watcher');
watcher.subscribe(".", (err, events) => {
  console.log(events);
});

Interestingly, all those variants with @REM do not reproduce this problem, so there must be something very particular about piping the whole output at high rates.

@bersbersbers
Copy link
Author

bersbersbers commented Jun 28, 2024

And even more interestingly, events start coming in as soon as I read the file in another process. E.g., it can be enough to run watcher.bat in one terminal, see that no events are seen at all, only to then see them come in after I run more watcher.log in another terminal. Very strange.

@bersbersbers
Copy link
Author

bersbersbers commented Jun 28, 2024

It seems this module is using ReadDirectoryChangesW on Windows, which is known to miss events in high-activity scenarios. However, here it seems the module is missing all events, which makes me wonder if this is a different issue.

@bersbersbers
Copy link
Author

And even more interestingly, events start coming in as soon as I read the file in another process.

Current workaround: a background process doing something like

monitor-logs.bat

start /min "Monitor log files..." cmd /k for /l %%i in () do @(for %%f in (C:\log\*.txt) do @dir /b %%f ^> nul)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant