microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.24k stars 28.56k forks source link

FileSystemWatcher may miss event when many changes are happening in a short order #220039

Closed cdietrich closed 2 weeks ago

cdietrich commented 2 months ago

Register a file System watcher

const w = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(vscode.workspace.workspaceFolders![0],"*.txt"));
w.onDidDelete((e) => {
    console.log(e);
    counter++;
});

do a deletion of a huge number of files (would also happen on creation) then the watch may omit some changes

(when used together with a language server/vscode-language-client this will be bad a the state in the server might become out of sync)

here is an attempt to write a reproducing test

https://github.com/cdietrich/fs-watcher-bug/blob/main/src/test/extension.test.ts

originally reported as https://github.com/microsoft/vscode-languageserver-node/issues/1503

cc @dbaeumer

ocallesp commented 1 month ago

This bug is also affecting the Test Explorer in C# DevKit (https://github.com/microsoft/vscode-dotnettools/issues/996), causing it to miss some test methods. This issue is disrupting the user experience significantly on our end.

I have a repro case in VS Code v1.92.0-insider (Universal) where after opening a solution with 10 projects and performing a build, the Test Explorer shows incomplete test projects.

@bpasero is there any milestone set for resolving this bug ?

bpasero commented 1 month ago

Would be great to distill a reproducible case using https://github.com/parcel-bundler/watcher, which is the file watcher we leverage so that it can be reported upstream, if it turns out to be.

cdietrich commented 1 month ago

@bpasero maybe https://github.com/cdietrich/parcel-watcher-bug helps funny thing. when installing and using watchman as backend (under mac) the results are ok so there seems to be a diff in parcel-watcher and watchmans usage of apples api

as we seem to have problems also on linux (but i dont see it with the test above - ok sometimes it gets 0 changes). i also need to further investigate. does vscode use a specific backend for linux?

bpasero commented 1 month ago

@cdietrich here is my output on macOS:

~/Desktop/parcel-watcher-bug> node index.js
1001
counter 1000
1
~/Desktop/parcel-watcher-bug> 

What do you get?

We use the standard backend for parcel watcher, so it would be inotify on Linux.

cdietrich commented 1 month ago

if i run multiple times it will say

counter 567 or counter 998 or counter 867

on linux its much much more seldom

cdietrich commented 1 month ago

from my m2 pro

while ./node_modules/.bin/ts-node index.ts; do :; done
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 779
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 1000
1
1001
counter 593
1
1001
counter 1000
1
1001

on my private m1 air much more often.

bpasero commented 1 month ago

@cdietrich got it, I would think you can report this with your repro at https://github.com/parcel-bundler/watcher

cdietrich commented 1 month ago

done https://github.com/parcel-bundler/watcher/issues/183

bpasero commented 1 month ago

Thanks a ton for the issue and repro, thats helpful, I am going ahead and close this as upstream. I am monitoring the parcel repository for fixes.

bpasero commented 3 weeks ago

Re-opening to keep understanding the issue https://github.com/microsoft/vscode-dotnettools/issues/996 and whether that is the same underlying problem.

@ocallesp curious if you can be certain that this issue is really the same issue?

vs-code-engineering[bot] commented 2 weeks ago

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!