fix(cli): never let the update check block up/init (#418) - #422
Open
HusseinAdeiza wants to merge 1 commit into
Open
HusseinAdeiza wants to merge 1 commit into
HusseinAdeiza wants to merge 1 commit into
Conversation
) `up` and `init` await `checkCliVersion()` as their first step, before Docker is consulted. That method awaited `update-check` with no deadline and no try/catch, so the unauthenticated npm registry request could abort the whole command: $ node dist/index.js up --headless - Checking CLI version... TypeError: Cannot read properties of undefined (reading 'code') at getMostRecent (node_modules/update-check/index.js:125:11) at async SimulatorService.checkCliVersion (dist/index.js:59025:20) at async StartAction.execute (dist/index.js:59385:5) Confirmed failure modes of update-check@1.5.4: an unreachable or blackholed registry, a 5xx, a proxy login page served with 200, and a cache file left truncated by an interrupted run. It also rejects on timeout without destroying the request socket, so the promise settles while the event loop stays held and the process hangs instead of exiting. An upgrade notice is cosmetic and must not gate startup, so bound the call with a short deadline and treat every failure as "no update information". The warning still prints when the check succeeds in time. Adds regression tests for each failure mode plus the timeout path.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This branch has not been deployed
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.
Summary
Fixes #418.
upandinitawaitSimulatorService.checkCliVersion()as their very first step, before Docker is ever consulted. That method awaitedupdate-checkwith no deadline and notry/catch, so the unauthenticated npm-registry request could take down the whole command.Reproduced on
v0.40-dev(commit48d1223) with the registry blackholed:I measured each failure mode of
update-check@1.5.4against a stub registry:TypeErrorError: Request failed with code 500SyntaxError: Unexpected token '<'SyntaxError: Unexpected end of JSON inputThere is a second, separate effect worth calling out. When the request times out,
update-checkcallsreject()without destroying the request, so the socket stays open and the event loop never drains. The promise settles, but the process remains alive and idle. That matches the reported symptom more precisely than the crash above.The fix
An upgrade notice is cosmetic, so it must not gate startup:
updateCheck()withCLI_VERSION_CHECK_TIMEOUT_MS(2s, exported fromsrc/lib/config/simulator.tsnext to the other timeout constants)unref'd so it cannot itself keep the process aliveAfter the fix, the same blackholed-registry run advances past
Checking CLI version...into the Docker stage, which is where it belongs.Tests
Six new cases in
tests/services/simulator.test.ts, one per row of the table above plus the timeout path and a control asserting the warning still fires.I confirmed they are not tautological: with the fix body reverted, 5 of the 6 fail, and all 6 pass with it restored.
Verification
npx vitest run— 818 passedtsc --noEmit— clean for the touched files (the one pre-existingstakingWizard.test.tserror is unrelated and present on the base commit).github/scripts/validate-branch-policy.sh— ok forv0.40-devas the active dev branchtests/libs/keychainManager.test.tsfails locally becausekeytar's native binary is not built in this environment. That failure is pre-existing on the base commit and unrelated to this change; CI installslibsecretand builds it.Per CONTRIBUTING.md the target is the
v0.40-devintegration branch, notmain, so this PR is opened againstv0.40-dev.Note on scope
I kept the fix in the CLI rather than bumping
update-check, since the socket leak and the fragileerr.codeaccess are upstream bugs. The deadline plus thecatchmakes the CLI resilient to both without depending on an upstream release. Happy to revisit if maintainers would rather take the upgrade path.