Skip to content

watch: cancel pending restart on shutdown - #63383

Merged
nodejs-github-bot merged 4 commits into
nodejs:mainfrom
trivikr:watch-hang-completed-child-terminate
Jun 4, 2026
Merged

watch: cancel pending restart on shutdown#63383
nodejs-github-bot merged 4 commits into
nodejs:mainfrom
trivikr:watch-hang-completed-child-terminate

Conversation

@trivikr

@trivikrtrivikr commented May 17, 2026

Copy link
Copy Markdown
Member

Fixes a watch mode shutdown race where a pending debounced file change could still emit after FilesWatcher.clear() closed the active watchers. That allowed watch mode to restart the child process after shutdown had already started, which could leave out/Release/node --watch --inspect processes behind and fail CI’s leftover-process check.

This cancels the pending debounce timer during watcher cleanup and makes watched child exit handling stable across overlapping restart/shutdown paths.

Noticed while examining flaky tests in ubuntu2404_sharedlibs_shared_x64/56356

13:35:08 All tests passed.13:35:08 ps awwx | grep Release/node | grep -v grep | cat13:35:08 2405720 ? Sl 0:00 /home/iojs/build/workspace/node-test-commit-linux-containered/out/Release/node --inspect=0 --watch /home/iojs/build/workspace/node-test-commit-linux-containered/test/fixtures/watch-mode/inspect.js13:35:08 2405726 ? Sl 0:00 /home/iojs/build/workspace/node-test-commit-linux-containered/out/Release/node --inspect=0 /home/iojs/build/workspace/node-test-commit-linux-containered/test/fixtures/watch-mode/inspect.js13:35:08 make[1]: *** [Makefile:648: test-ci] Error 113:35:08 make: *** [Makefile:674: run-ci] Error 213:35:08 Build step 'Conditional steps (multiple)' marked build as failure

Testing

The updated unit tests were run before/after

Before

$ python3 tools/test.py -J --mode=release \ parallel/test-watch-mode-files_watcher-clear \ sequential/test-watch-mode-inspect \ parallel/test-watch-mode-files_watcher=== release test-watch-mode-files_watcher-clear ===Path: parallel/test-watch-mode-files_watcher-clearnode:assert:173 throw err; ^AssertionError [ERR_ASSERTION]: function should not have been called at file:///Users/trivikram/workspace/node/test/parallel/test-watch-mode-files_watcher-clear.mjs:45called with arguments: { owners: SafeSet(0) {}, eventType: 'change' } at FilesWatcher.mustNotCall (/Users/trivikram/workspace/node/test/common/index.js:567:12) at FilesWatcher.emit (node:events:509:20) at Timeout._onTimeout (node:internal/watch_mode/files_watcher:104:12) at listOnTimeout (node:internal/timers:605:17) at process.processTimers (node:internal/timers:541:7) { generatedMessage: false, code: 'ERR_ASSERTION', actual: undefined, expected: undefined, operator: 'fail', diff: 'simple'}Node.js v27.0.0-preCommand: out/Release/node --expose-internals /Users/trivikram/workspace/node/test/parallel/test-watch-mode-files_watcher-clear.mjs[00:03|% 100|+ 2|- 1]: DoneFailed tests:out/Release/node --expose-internals /Users/trivikram/workspace/node/test/parallel/test-watch-mode-files_watcher-clear.mjs

After

$ python3 tools/test.py -J --mode=release \ parallel/test-watch-mode-files_watcher-clear \ sequential/test-watch-mode-inspect \ parallel/test-watch-mode-files_watcher[00:03|% 100|+ 3|- 0]: DoneAll tests passed.

Assisted-by: openai:gpt-5.5

@nodejs-github-botnodejs-github-bot added the needs-ci PRs that need a full CI run. label May 17, 2026
@trivikr
trivikrforce-pushed the watch-hang-completed-child-terminate branch from c0a9c2b to 7f3594dCompareMay 17, 2026 15:45
@codecov

codecovBot commented May 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.32%. Comparing base (c55b126) to head (2bff1af).
⚠️ Report is 120 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #63383 +/- ##
==========================================
+ Coverage 90.26% 90.32% +0.06% 
==========================================
Files 730 730 Lines 234004 234164 +160 Branches 43829 43913 +84 ==========================================
+ Hits 211223 211515 +292 + Misses 14502 14386 -116 + Partials 8279 8263 -16 
Files with missing linesCoverage Δ
lib/internal/watch_mode/files_watcher.js91.28% <100.00%> (+0.58%)⬆️

... and 35 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.

@trivikrtrivikr added watch-mode Issues and PRs related to watch mode request-ci Add this label to start a Jenkins CI on a PR. labels May 18, 2026
Comment threadtest/sequential/test-watch-mode.mjs Outdated
Comment threadtest/parallel/test-watch-mode-files_watcher-clear.mjs Outdated
Comment threadtest/parallel/test-watch-mode-files_watcher-clear.mjs
@trivikr
trivikrforce-pushed the watch-hang-completed-child-terminate branch from 279375b to 7cbef16CompareMay 19, 2026 21:44
trivikrand others added 4 commits May 24, 2026 18:42
Cancel any pending FilesWatcher debounce timer when watch mode clears
its watchers. This prevents a queued change event from restarting the
watched process after shutdown has started.
Keep the watched child exit handling attached for the lifetime of the
child so overlapping restart and shutdown paths do not remove each
other's exit listeners.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@trivikr
trivikrforce-pushed the watch-hang-completed-child-terminate branch from 5bf517b to 2bff1afCompareMay 25, 2026 01:43
@trivikr
trivikr requested a review from aduh95May 25, 2026 04:50
@trivikrtrivikr added the review wanted PRs that need reviews. label May 26, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 28, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikrtrivikr added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed review wanted PRs that need reviews. labels May 28, 2026
@trivikr

Copy link
Copy Markdown
MemberAuthor

Requested review from folks who'd recently contributed to watch mode.

@trivikr

Copy link
Copy Markdown
MemberAuthor

I'll request merge in a couple of days, if there's no additional feedback.

@trivikrtrivikr added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jun 4, 2026
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 4, 2026
@nodejs-github-bot
nodejs-github-bot merged commit cb8eebf into nodejs:mainJun 4, 2026
81 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in cb8eebf

aduh95 pushed a commit that referenced this pull request Jun 18, 2026
Cancel any pending FilesWatcher debounce timer when watch mode clears
its watchers. This prevents a queued change event from restarting the
watched process after shutdown has started.
Keep the watched child exit handling attached for the lifetime of the
child so overlapping restart and shutdown paths do not remove each
other's exit listeners.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: #63383
Reviewed-By: Tim Perry <pimterry@gmail.com>
aduh95 pushed a commit that referenced this pull request Jun 25, 2026
Cancel any pending FilesWatcher debounce timer when watch mode clears
its watchers. This prevents a queued change event from restarting the
watched process after shutdown has started.
Keep the watched child exit handling attached for the lifetime of the
child so overlapping restart and shutdown paths do not remove each
other's exit listeners.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: #63383
Reviewed-By: Tim Perry <pimterry@gmail.com>
@trivikr
trivikr deleted the watch-hang-completed-child-terminate branch July 13, 2026 05:15
aduh95 pushed a commit that referenced this pull request Jul 30, 2026
Cancel any pending FilesWatcher debounce timer when watch mode clears
its watchers. This prevents a queued change event from restarting the
watched process after shutdown has started.
Keep the watched child exit handling attached for the lifetime of the
child so overlapping restart and shutdown paths do not remove each
other's exit listeners.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: #63383
Reviewed-By: Tim Perry <pimterry@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.needs-ciPRs that need a full CI run.watch-modeIssues and PRs related to watch mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@trivikr@nodejs-github-bot@pimterry@aduh95