Repository navigation
fix(scripts): bound shadcn-sync registry requests with a 10s timeout - #4715
Conversation
fetchUrl() used https.get with only 'error'/'end' wired up, so a
black-holed connection (dropped SYN, or a peer that completes the TCP
handshake and never responds) hung forever. --check makes 46 of these
in series, so one hang stalled the whole command.
req.setTimeout(10_000, ...) now destroys the request with an error
naming the timed-out URL; the existing req.on('error', reject) picks
it up, reusing the same rejection path --check/--update already
handle. No retry: a black hole doesn't resolve in seconds, so a retry
only doubles the worst-case wait. The 20-minute CI job backstop from
#4174 is unchanged.
Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnQd8iMMUwXQEV1crFmQiQ
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Review verdict: ACCEPT (reviewer of record, PM session Verified against this PR, not the report: exactly two changed files, Will flip ready + enable auto-merge once Lint, Type Check, and Test shards 1–4 conclude Generated by Claude Code |
Fixes #4031
What
fetchUrl()inscripts/shadcn-sync.jsusedhttps.getwith onlyerror/endwired up, so a black-holed connection — a dropped SYN, or a peer that completes the TCP handshake and then never writes a byte — hung forever.--checkfires 46 of these in series, so one hang stalled the whole command, bounded by nothing but the CI job'stimeout-minutes: 20backstop from #4174.req.setTimeout(10_000, () => req.destroy(new Error(...)))now bounds every request: on fire it destroys the request with an error naming the URL that hung, and the existingreq.on('error', reject)picks it up — reusing the same rejection path--check(marks the componenterror) and--update(refuses to write) already had, rather than adding a second one.timeoutMsis threaded throughfetchRegistrytoo, defaulting to the same 10s, so tests can drive it down without waiting out the real value.Per the delegated adjudication on the issue thread (2026-08-10 measurements: healthy path ~37ms/request, 10s ≈ 270x headroom, all 30 historical runs complete in 19-49s): 10s per request, no retry — a black hole doesn't resolve in seconds, so a retry only doubles the worst-case wait while the existing error path already degrades gracefully. The 20-minute job backstop from #4174 is unchanged; this is the real fix it was standing in for.
Why both a real socket and a double are in the test file
Two network conditions produce the hang — a dropped SYN (connection never completes) and a peer that completes the handshake and then never responds — and both are covered by the same
req.setTimeoutcallback (Node arms that idle timer as soon as a socket is assigned to the request, before the handshake resolves).The committed coverage uses a
getdouble that mimics a stuckClientRequest(deterministic, exercises the exactsetTimeout/destroy(error)/error-listener wiringfetchUrldepends on). A real raw-nethung-socket server was also used and is not committed: it reproduced correctly and fast (~40-50ms against a 40mstimeoutMs) as a standalone Node script and inside aworker_threadsWorker, including while this shared dev container had a sibling agent's heavypnpm buildpegging multiple cores — but the identical code run through Vitest'sthreadspool under that same load reliably failed to observe the timeout at all (not slow — silent for a 20sit()bound, reproducing with-tisolating the one test and with--maxWorkers=1). That's a Vitest-threads-pool-under-contention interaction with the real socket timer, not a defect infetchUrl, and this repo's own flaky-test discipline (AGENTS.md, "flaky 测试") is explicit that widening a budget to paper over a race is the wrong fix — here even 20s didn't turn a genuine non-event into a passing one. So the real-socket path is verified manually (below) instead of committed.Manual end-to-end verification (real CLI, real hang)
Temporarily pointed the
accordionentry inpackages/components/shadcn-components.jsonat a local raw-netserver that accepts the connection and never responds (reverted before commit —git statusconfirms the manifest is unchanged in this PR):md5sum packages/components/src/ui/accordion.tsxbefore/after--updateis identical, andgit statusshows no write —--updaterefuses exactly as before. Both commands: fast-fail after the real 10s default, error text names the exact URL that hung, exit code and error marking unchanged from the existing error path.Healthy-path regression check
The sandbox's egress blocker returns
HTTP 403immediately (not a black hole) for the realui.shadcn.com, sopnpm shadcn:check's 46 requests can't hit the real registry here — but that's itself the useful check: all 46 fail via immediate403, total wall time 0.481s, zero timeouts triggered. The newreq.setTimeoutdoesn't interfere with or slow down the existing fast-response error path.Tests
scripts/__tests__/shadcn-sync-fetch-cache.test.ts— newdescribeblock: agetdouble that never invokes its response callback times out at the configuredtimeoutMs, names the URL, and propagates throughfetchRegistrywithout writing to the cache; a false-positive guard confirms a normal fast response is unaffected.All at
995a6fdad(git rev-parse --short HEADafter the final commit).Scope
Only
scripts/shadcn-sync.jsand its test file changed. No changeset:scripts/is repo tooling, not part of the.changeset/config.jsonfixedrelease group —check-changeset-presence.mjsconfirms none is owed. This repo has noskip-changesetlabel, so none is applied.Generated by Claude Code