Skip to content

watch: strip watch flags from NODE_OPTIONS in child process#62143

Open
marcopiraccini wants to merge 1 commit intonodejs:mainfrom
marcopiraccini:fix/watch-node-options-infinite-loop
Open

watch: strip watch flags from NODE_OPTIONS in child process#62143
marcopiraccini wants to merge 1 commit intonodejs:mainfrom
marcopiraccini:fix/watch-node-options-infinite-loop

Conversation

@marcopiraccini
Copy link
Contributor

@marcopiraccini marcopiraccini commented Mar 7, 2026

When NODE_OPTIONS contains --watch, the watch mode parent process spawns a child that inherits the same NODE_OPTIONS, causing the child to also enter watch mode and spawn another child, creating an infinite loop of process spawning.

This PR strips watch-related flags (--watch, --watch-path,--watch-preserve-output, --watch-kill-signal) from NODE_OPTIONS before passing the environment to the child process. This mirrors the existing logic that already strips these flags from process.execArgv.

Non-watch flags in NODE_OPTIONS (e.g., --max-old-space-size) are preserved.

Fixes: #61740

This is actually similar to #61838 but more "surgical", it just avoid propagating watch flags.

Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Mar 7, 2026
@marcopiraccini marcopiraccini marked this pull request as ready for review March 7, 2026 05:56
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.65%. Comparing base (3725bd2) to head (bb649d4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62143      +/-   ##
==========================================
- Coverage   89.65%   89.65%   -0.01%     
==========================================
  Files         676      676              
  Lines      206543   206543              
  Branches    39547    39548       +1     
==========================================
- Hits       185184   185178       -6     
- Misses      13480    13487       +7     
+ Partials     7879     7878       -1     

see 28 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

watch: NODE_OPTIONS=--watch causes infinite loop

2 participants