`fs.watch`: endless file events reported
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
Version
v22.21.1
Platform
Microsoft Windows NT 10.0.26200.0 x64
Subsystem
No response
What steps will reproduce the bug?
- create a folder
vscode - run this command in that folder
mkdir .vscode && echo {"editor.fontSize": 33}>.vscode\settings.json - run the following node.js script in a terminal pointing to the folder
vscode/.vscode - run this command in that folder
rmdir /s /q .vscode\ && mkdir .vscode && echo {"editor.fontSize": 33}>.vscode\settings.json
const fs = require("fs");
fs.watch("<path to a folder>/.vscode", (eventType, filename) => {
if (filename) {
console.log(`Event Type: ${eventType}`);
console.log(`Filename: ${filename}`);
} else {
console.log("Filename not provided");
}
});
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior? Why is that the expected behavior?
After running the last command there should be change events reported in an endless fashion.
What do you see instead?
Endless reports of:
Filename: \\?\C:\Users\bpasero\Desktop\testing-watcher\.vscode
Event Type: rename
Filename: \\?\C:\Users\bpasero\Desktop\testing-watcher\.vscode
Event Type: rename
Filename: \\?\C:\Users\bpasero\Desktop\testing-watcher\.vscode
Event Type: rename
Filename: \\?\C:\Users\bpasero\Desktop\testing-watcher\.vscode
Event Type: rename
Additional information
Originally reported in VS Code repo as https://github.com/microsoft/vscode/issues/287800
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the fs.watch API and reproduce the Windows sequence using the provided Node.js script. Compare the repeated rename events and path values with the stated expected behavior, then trace the Windows file-watching path. Done means the reproduction no longer produces unintended endless events and the relevant behavior is covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100