Skip to content

File watcher (Linux): nothing in a folder created together with its subfolders is ever reported, nor any later change in it #350854

Duplicate

Description

Does this issue occur when all extensions are disabled?: Yes (the reproduction is an extension test run with
--disable-extensions; it uses only vscode.workspace.createFileSystemWatcher)

  • VS Code Version: 1.140.0
  • OS Version: Linux aarch64 (Fedora kernel 7.1.10, in a Podman container on Xvfb), 8 CPUs

When a folder is created in the workspace with a subfolder right after it (mkdir -p a/b, a checkout, an unpacked
archive) or is moved into the workspace with content, the recursive watcher reports the top folder but often nothing
inside it: not the subfolder, not its files, and none of the later changes to them for the rest of the session. An
extension's FileSystemWatcher, and so a language server's workspace/didChangeWatchedFiles, never hears that a file
in the subfolder was deleted. Our language server kept the deleted file's errors in the Problems view.

Steps to reproduce (an extension test, @vscode/test-electron, a folder opened as the workspace):

const root = vscode.workspace.workspaceFolders![0].uri.fsPath;
const events: string[] = [];
const watcher = vscode.workspace.createFileSystemWatcher('**/*');
watcher.onDidCreate(uri => events.push('created ' + path.relative(root, uri.fsPath)));
watcher.onDidDelete(uri => events.push('deleted ' + path.relative(root, uri.fsPath)));

// a file in a folder that is watched: once it is reported, every event before it has been delivered
let n = 0;
async function barrier() {
    const name = `sentinel-${n++}`;
    const heard = new Promise<void>(resolve => {
        const listener = watcher.onDidCreate(uri => {
            if (path.relative(root, uri.fsPath) === name) { listener.dispose(); resolve(); }
        });
    });
    await fs.writeFile(path.join(root, name), 'x');
    await heard;
}

for (let i = 0; i < 30; i++) {
    const top = `case-${i}`;
    await fs.mkdir(path.join(root, top, 'b'), { recursive: true });
    await fs.writeFile(path.join(root, top, 'b', 'one.txt'), '1');
    await fs.writeFile(path.join(root, top, 'b', 'two.txt'), '2');
    await barrier();
    await fs.unlink(path.join(root, top, 'b', 'two.txt'));
    await barrier();
    const seen = (what: string) => events.includes(what);
    console.log(top, seen(`created ${top}`), seen(`created ${top}/b`), seen(`deleted ${top}/b/two.txt`));
}

Expected: every iteration reports case-i, case-i/b, its two files, and the deletion of case-i/b/two.txt.

Actual, from the same test with a folder case-i/Project holding three files, over several sets of iterations in one
window:

How the folder is made Lost b, its files and the later deletion
mkdir -p and writes, machine otherwise idle 2 of 60
the same, with 8 busy loops on the 8 CPUs 10 of 30 (5 of the 30 also lost a file written in case-i itself)
made outside the workspace, then renamed into it 5 of 5 (nothing inside reported)
one folder at a time, each made once its own event came 0 of 5

case-i itself was reported every time. In every iteration that missed b, the later deletion in it was missed too.
b has no watch, so nothing that changes in it later can be reported.

Where it comes from: on Linux the recursive watcher is @parcel/watcher's inotify backend. On IN_CREATE or IN_MOVED_TO of
a directory, InotifyBackend::handleSubscription adds the new directory to its tree and calls watchDir. That one
inotify_add_watch neither reads the directory's entries nor recurses. Anything created in it before the watch was
added produces no event. A subdirectory created in that window never gets a watch, so everything under it stays unseen.
inotify(7) describes this race and advises scanning a new subdirectory once its watch is added. parcelWatcher.ts
passes parcel's events on and does not scan a created folder. In parcel-bundler/watcher#185, which reports the same
thing on macOS and Windows for a folder restored from the trash, the maintainer suggested that consumers assume a
created directory may have children.

Suggested fix: when the watcher reports a folder ADDED, scan it (bounded) and report what is in it as ADDED. Make sure
its subfolders get watched as well, either by fixing parcel's watchDir to scan and recurse after adding the watch, or by
restarting the affected subscription. Reporting the scan without watching the subfolders would still lose every later
change in them.

Activity

  1. lagergren commented on Nov 28, 2026

    @lagergren
    Author

    Closing this as a duplicate of #227252, which is tracked upstream as parcel-bundler/watcher#97 (the inotify backend's watchDir doesn't scan or recurse into a newly created folder). I'm adding the reproduction and the rates from this issue there, including the folder moved in with content and the later changes that are never reported. Sorry for the duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions