test: fix flaky test-watch-mode-inspect timeout#63361
Open
mcollina wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #63361 +/- ##
==========================================
- Coverage 90.06% 90.05% -0.01%
==========================================
Files 714 714
Lines 225367 225522 +155
Branches 42593 42645 +52
==========================================
+ Hits 202966 203103 +137
- Misses 14182 14197 +15
- Partials 8219 8222 +3 🚀 New features to boost your workflow:
|
This test randomly times out (~120s) on CI due to a race condition between child-process restart (triggered by touching the watched file) and the second inspector-session connection. The old code used an interval-based restart (write every 500ms) and a 'gettingDebuggedPid' flag to pause writes during a session. This still left a race window where getDebuggedPid() would attempt to connect the inspector via HTTP GET /json/list + WebSocket upgrade either before the new child was ready (empty target list) or after the old session was being destroyed, causing the promise to hang. Fix: Replace the interval with a single write that triggers exactly one restart, then wait for the restarted child's 'safe to debug now' stdout line before connecting the second inspector session. This eliminates the race by ensuring the new child process and its inspector session are fully ready before any connection attempt. Removes the now-unused gettingDebuggedPid flag and the pending setTimeout delay that was needed as a backstop for the interval. Fixes: nodejs#44898 Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: nodejs#63361
cad4400 to
49b6ea5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a persistent flaky timeout in
test-watch-mode-inspect(marked FLAKY in , issue #44898).Root Cause
A race condition between child-process restart and inspector-session connection:
--inspect=0and--watchresetPort()/json/list+ upgrade races against the restart:/json/listmay return an empty array (no targets yet) →response[0]throws → promise hangsFix
Replace the interval-based restart (write every 500ms, paused by a
gettingDebuggedPidflag) with a single write + readiness gate:restartAndWaitForReady(file, instance)writes the file once and returns a promise that resolves when the restarted child printssafe to debug nowon stdoutgetDebuggedPidcall only fires after that promise resolves — guaranteeing the new child and its inspector session are fully readyRemoves the now-unused
gettingDebuggedPidflag and thesetTimeoutbackstop.Validation
Both tests pass locally with the fix. The ordering is now deterministic:
Closes: #44898