Skip to content

Deno.watchFs emits events for wrong directory when multiple watchers are running #32660

@wegrzynkiewicz

Description

@wegrzynkiewicz

Version: Deno: 2.7.5
System: Linux Mint Debian Edition 6 (faye), kernel 6.1.0-42-amd64 (x86_64)

Description

When running two concurrent Deno.watchFs watchers on separate directories, renaming a file in one directory causes the other watcher to emit events for that file, even though the file is not in its watched path.

Reproduction script

const path1 = `/app/assets1`
const path2 = `/app/assets2`

async function watch1() {
  console.log(`watch1 ${path1}`);
  for await (const { kind, paths } of Deno.watchFs(path1)) {
    console.log("detect 1", kind, paths)
  }
}

async function watch2() {
  console.log(`watch2 ${path2}`);
  for await (const { kind, paths } of Deno.watchFs(path2)) {
    console.log("detect 2", kind, paths)
  }
}

void watch1()
void watch2()

Steps to reproduce

  • Run the script: deno run -A watch.ts
  • Rename a file inside: mv /app/assets1/test.png /app/assets1/test.renamed.png

Actual output

watch1 /app/assets1
watch2 /app/assets2
detect 1 remove [ "/app/assets1/test.png" ]
detect 2 remove [ "/app/assets1/test.png" ]
detect 1 rename [ "/app/assets1/test.renamed.png" ]
detect 2 remove [ "/app/assets1/test.png", "/app/assets1/test.renamed.png" ]
detect 1 rename [ "/app/assets1/test.png", "/app/assets1/test.renamed.png" ]

Expected behavior

The watcher for /app/assets2 should not emit any events for a file change that occurred in /app/assets1. Events from detect two should only fire when files inside /app/assets2 are modified.

Metadata

Metadata

Assignees

No one assigned

    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