Uh oh!
There was an error while loading. Please reload this page.
fix(core): unref the CDP deadline so it can't delay process exit - #2405
Open
rishigupta1599 wants to merge 1 commit into
Open
fix(core): unref the CDP deadline so it can't delay process exit#2405rishigupta1599 wants to merge 1 commit into
rishigupta1599 wants to merge 1 commit into
Conversation
The deadline added for stalled-browser recovery is a watchdog, but it was holding the event loop open. An orphaned send - one whose reply is never coming, which happens routinely when a page closes with a Fetch.continueResponse still in flight - keeps a live timer for the full deadline. The work is already finished at that point, so the CLI sits idle for up to two minutes after printing "Finalized build" before exiting. Observed intermittently (once in four runs) on a real storybook capture: the run went quiet after finalizing and exited 116s later, when the deadline fired. Unref matches the existing precedent in server.js, and the timer still fires normally while anything else keeps the loop alive. Verified with a probe process holding one orphaned send at a 30s deadline: exits in 346ms unref'd, 30162ms ref'd.
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 freeto 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.
Summary
Follow-up to the CDP send deadline. The deadline is a watchdog, but its timer was not
unref'd, so it holds the Node event loop open.An orphaned send — one whose reply is never coming — leaves that timer live for the full deadline. This is not exotic: it happens routinely when a page closes with a
Fetch.continueResponsestill in flight. By then the real work is done, so the CLI sits idle for up to two minutes after printingFinalized build #…before exiting.I hit this intermittently (once in four runs) while capturing a real Storybook: the run went quiet after finalizing and exited 116s later, exactly when the deadline fired.
A watchdog should never be the reason a process cannot exit.
unref()matches the existing precedent inserver.js, and the timer still fires normally whenever anything else is keeping the loop alive — which is the case for every send that matters.Test plan
Two new specs (one per send path) capture the created timer and assert
hasRef() === false, so a future change that re-refs the watchdog fails the suite.All 13 specs in
packages/core/test/unit/session.test.jspass;eslintclean.Verified in a real process with a probe holding one orphaned send at a 30s deadline:
Notes
.unref()rather than.unref?.():server.js:226already does the same, and an optional call would add a branch whose false arm is unreachable in Node, breaking the 100% branch-coverage gate.global.setTimeoutto capture the deadline, and hands the realsetTimeoutto the callback so its own waits aren't captured — otherwise there's no telling which timer is which.🤖 Generated with Claude Code