Skip to content

--watch combined with --watch-path results in duplicate restart events/logs #57124

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

Closed
OliverJAsh opened this issue Feb 18, 2025 · 3 comments · Fixed by #57936 or #58279
Closed

--watch combined with --watch-path results in duplicate restart events/logs #57124

OliverJAsh opened this issue Feb 18, 2025 · 3 comments · Fixed by #57936 or #58279

Comments

@OliverJAsh
Copy link

OliverJAsh commented Feb 18, 2025

Version

22.13.1

Platform

Darwin macbookpro.lan 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000 arm64 arm Darwin

Subsystem

No response

What steps will reproduce the bug?

Full reduced test case: https://github.com/OliverJAsh/node-watch-bug

src/server.js:

setTimeout(() => {}, 100000);
  1. Run node --watch --watch-path=./src/ ./src/server.js
  2. In another terminal run touch ./src/server.js.

How often does it reproduce? Is there a required condition?

Every time.

What is the expected behavior? Why is that the expected behavior?

1 restart event/log:

Restarting './src/server.js'

This is what we get when we remove --watch and only specify --watch-path:

$ node --watch-path=./src/ ./src/server.js
Restarting './src/server.js'

Curiously, this is also the behaviour we get if we add --watch-preserve-output:

$ node --watch --watch-preserve-output --watch-path=./src/ ./src/server.js
Restarting './src/server.js'

What do you see instead?

2 restart events/logs:

$ node --watch --watch-path=./src/ ./src/server.js
Restarting './src/server.js'
Restarting './src/server.js'

Additional information

This part of the docs seems relevant:

This will turn off watching of required or imported modules, even when used in combination with --watch.

https://nodejs.org/docs/latest-v22.x/api/cli.html#--watch-path

Potentially related: #55189

@juanarbol
Copy link
Member

Ping @nodejs/libuv

macOS is quite messy with the watcher 🫠💔

@bnoordhuis
Copy link
Member

Libuv passes on the events it receives from FSEvents more or less verbatim, it doesn't do debouncing. If node needs that, it needs to implement it itself.

@dario-piotrowicz
Copy link
Member

I'm reopening this since the PR that fixed this issue (#57936) unfortunately needed to be reverted

I will look soon into reintroducing the fix 😓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants