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

BUG - watcher from Deno.watchFs creating duplicate events if closed and created again on windows #27742

Open
MrMysterius opened this issue Jan 20, 2025 · 0 comments

Comments

@MrMysterius
Copy link

On Windows closing a Deno.FsWatcher doesn't correctly close it and still keeps watching separately a path. Which then causes duplicate events on other created Deno.FsWatcher's

Script 1:

let watcher = Deno.watchFs(".", { recursive: false });

setTimeout(() => {
  watcher.close();
}, 300);

for await (const event of watcher) {
  console.log("WATCHER 1 >>>> event", event);
}
console.log("1");

watcher = Deno.watchFs(".", { recursive: false });

setTimeout(() => {
  watcher.close();
}, 300);

for await (const event of watcher) {
  console.log("WATCHER 2 >>>> event", event);
}
console.log("2");

watcher = Deno.watchFs(".", { recursive: false });

setTimeout(() => {
  watcher.close();
}, 300);

for await (const event of watcher) {
  console.log("WATCHER 3 >>>> event", event);
}
console.log("3");

watcher = Deno.watchFs(".", { recursive: false });

for await (const event of watcher) {
  console.log("WATCHER 4 >>>> event", event);
}
console.log("4");

Output 1 [REDACTED] (used touch test.txt):

1
2
3
WATCHER 4 >>>> event [Object: null prototype] {
  kind: "modify",
  paths: [ "REDACTED\\test.txt" ],
  flag: null
}
WATCHER 4 >>>> event [Object: null prototype] {
  kind: "modify",
  paths: [ "REDACTED\\test.txt" ],
  flag: null
}
WATCHER 4 >>>> event [Object: null prototype] {
  kind: "modify",
  paths: [ "REDACTED\\test.txt" ],
  flag: null
}
WATCHER 4 >>>> event [Object: null prototype] {
  kind: "modify",
  paths: [ "REDACTED\\test.txt" ],
  flag: null
}

Script 2:

let watcher = Deno.watchFs(".", { recursive: false });

setTimeout(() => {
  watcher.close();
}, 300);

for await (const event of watcher) {
  console.log("WATCHER 1 >>>> event", event);
}
console.log("1");

watcher = Deno.watchFs(".", { recursive: false });

setTimeout(() => {
  watcher.close();
}, 300);

for await (const event of watcher) {
  console.log("WATCHER 2 >>>> event", event);
}
console.log("2");

watcher = Deno.watchFs(".", { recursive: false });

for await (const event of watcher) {
  console.log("WATCHER 3 >>>> event", event);
}
console.log("3");

Output 1 [REDACTED] (used touch test.txt):

1
2
WATCHER 3 >>>> event [Object: null prototype] {
  kind: "modify",
  paths: [ "REDACTED\\test.txt" ],
  flag: null
}
WATCHER 3 >>>> event [Object: null prototype] {
  kind: "modify",
  paths: [ "REDACTED\\test.txt" ],
  flag: null
}
WATCHER 3 >>>> event [Object: null prototype] {
  kind: "modify",
  paths: [ "REDACTED\\test.txt" ],
  flag: null
}

Version:

deno 2.1.6 (stable, release, x86_64-pc-windows-msvc)
v8 13.0.245.12-rusty
typescript 5.6.2

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