Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

fix(scripts): bound shadcn-sync registry requests with a 10s timeout - #4715

Merged
yinlianghui merged 1 commit into
mainfrom
claude/issue-4031-shadcn-sync-timeout
Aug 15, 2026
Merged

yinlianghui merged 1 commit into
mainfrom
claude/issue-4031-shadcn-sync-timeout

Conversation

@yinlianghui

Copy link
Copy Markdown
Contributor

Fixes #4031

What

fetchUrl() in scripts/shadcn-sync.js used https.get with only error/end wired 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. --check fires 46 of these in series, so one hang stalled the whole command, bounded by nothing but the CI job's timeout-minutes: 20 backstop 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 existing req.on('error', reject) picks it up — reusing the same rejection path --check (marks the component error) and --update (refuses to write) already had, rather than adding a second one. timeoutMs is threaded through fetchRegistry too, 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.setTimeout callback (Node arms that idle timer as soon as a socket is assigned to the request, before the handshake resolves).

The committed coverage uses a get double that mimics a stuck ClientRequest (deterministic, exercises the exact setTimeout/destroy(error)/error-listener wiring fetchUrl depends on). A real raw-net hung-socket server was also used and is not committed: it reproduced correctly and fast (~40-50ms against a 40ms timeoutMs) as a standalone Node script and inside a worker_threads Worker, including while this shared dev container had a sibling agent's heavy pnpm build pegging multiple cores — but the identical code run through Vitest's threads pool under that same load reliably failed to observe the timeout at all (not slow — silent for a 20s it() bound, reproducing with -t isolating the one test and with --maxWorkers=1). That's a Vitest-threads-pool-under-contention interaction with the real socket timer, not a defect in fetchUrl, 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 accordion entry in packages/components/shadcn-components.json at a local raw-net server that accepts the connection and never responds (reverted before commit — git status confirms the manifest is unchanged in this PR):

$ time node scripts/shadcn-sync.js --check
✗ accordion   Error fetching from registry: shadcn-sync: registry request timed out after 10000ms: https://127.0.0.1:45231/hang.json
[... other 45 components: real HTTP 403 from the sandbox's egress block, unaffected ...]
exit=0

$ time node scripts/shadcn-sync.js --update accordion
✗ Error updating accordion: shadcn-sync: registry request timed out after 10000ms: https://127.0.0.1:45231/hang.json

md5sum packages/components/src/ui/accordion.tsx before/after --update is identical, and git status shows no write — --update refuses 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 403 immediately (not a black hole) for the real ui.shadcn.com, so pnpm shadcn:check's 46 requests can't hit the real registry here — but that's itself the useful check: all 46 fail via immediate 403, total wall time 0.481s, zero timeouts triggered. The new req.setTimeout doesn't interfere with or slow down the existing fast-response error path.

Tests

scripts/__tests__/shadcn-sync-fetch-cache.test.ts — new describe block: a get double that never invokes its response callback times out at the configured timeoutMs, names the URL, and propagates through fetchRegistry without writing to the cache; a false-positive guard confirms a normal fast response is unaffected.

pnpm exec vitest run scripts/__tests__/shadcn-sync-fetch-cache.test.ts --maxWorkers=2
 Test Files  1 passed (1)
      Tests  26 passed (26)
   Duration  766ms (at 995a6fdad)

pnpm run type-check:scripts   # tsc -p tsconfig.scripts.json — 0 errors
node scripts/check-control-bytes.mjs   # ✅ OK (4238 files scanned)
pnpm run lint:root   # 0 errors, 22 pre-existing warnings, none in changed files
node scripts/check-changeset-presence.mjs   # ✅ no changeset owed (scripts/ isn't a released package)

All at 995a6fdad (git rev-parse --short HEAD after the final commit).

Scope

Only scripts/shadcn-sync.js and its test file changed. No changeset: scripts/ is repo tooling, not part of the .changeset/config.json fixed release group — check-changeset-presence.mjs confirms none is owed. This repo has no skip-changeset label, so none is applied.


Generated by Claude Code

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
@vercel

vercel Bot commented Aug 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
objectui Ignored Ignored Aug 15, 2026 3:47pm

Request Review

@github-actions github-actions Bot added the tests label Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

Review verdict: ACCEPT (reviewer of record, PM session session_01RnQd8iMMUwXQEV1crFmQiQ).

Verified against this PR, not the report: exactly two changed files, Fixes #4031 the only closing keyword, and the no-changeset call is grounded in the gate's own verdict (scripts/ is outside the fixed release group) rather than judgement. The implementation matches the delegated adjudication (10s, no retry, URL named in the error, existing rejection path reused, backstop from the earlier CI-timeout PR untouched), and the verification is layered the right way: the committed test is the deterministic double exercising the exact setTimeout/destroy/error-listener wiring, while the real-socket behavior is proven manually end-to-end (exact 10000ms fail naming the URL on both --check and --update, --update provably writing nothing, healthy path 0.481s with zero timeout firings) — and the decision NOT to commit the real-socket case is backed by a reproduced Vitest-threads-under-contention reading plus the repo's own no-budget-widening discipline, which is the honest call. Local gates pinned to 995a6fdad, matching this PR's current head.

Will flip ready + enable auto-merge once Lint, Type Check, and Test shards 1–4 conclude success on this head.


Generated by Claude Code

@yinlianghui
yinlianghui marked this pull request as ready for review August 15, 2026 16:01
@yinlianghui
yinlianghui added this pull request to the merge queue Aug 15, 2026
Merged via the queue into main with commit 21c4e52 Aug 15, 2026
18 checks passed
@yinlianghui
yinlianghui deleted the claude/issue-4031-shadcn-sync-timeout branch August 15, 2026 16:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shadcn-sync 的 registry 请求没有超时:连接被黑洞时 pnpm shadcn:check 会一直挂着(46 次串行请求)

2 participants