From accb1696064acd9be32b51f024de981343a3325a Mon Sep 17 00:00:00 2001 From: hello Date: Thu, 22 Oct 2026 11:06:06 +0800 Subject: [PATCH] fix(release): bound each npm attempt during a registry outage A degraded registry can hold whoami or view open for minutes, so the retry loops multiplied the wait instead of riding out a short outage. Bound each whoami to 30 seconds and each view to 30 seconds before retrying. --- .github/workflows/release.yml | 2 +- script/release-packages.mjs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0e44a1d5..5e490012 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -102,7 +102,7 @@ jobs: shell: bash run: | for attempt in $(seq 1 10); do - if npm whoami --registry=https://registry.npmjs.org; then exit 0; fi + if timeout 30 npm whoami --registry=https://registry.npmjs.org; then exit 0; fi echo "npm whoami failed (attempt ${attempt}/10); retrying after the registry settles" sleep 30 done diff --git a/script/release-packages.mjs b/script/release-packages.mjs index e1c0fa9c..d5d11c9d 100644 --- a/script/release-packages.mjs +++ b/script/release-packages.mjs @@ -38,9 +38,10 @@ function sleepSync(ms) { function npmView(spec, field) { let last for (let attempt = 1; attempt <= 4; attempt += 1) { - const result = spawnSync('npm', ['view', spec, field, '--json'], { cwd: ROOT, encoding: 'utf8' }) + const result = spawnSync('npm', ['view', spec, field, '--json'], { cwd: ROOT, encoding: 'utf8', timeout: 30_000 }) const failure = `${result.stderr ?? ''}${result.error?.message ?? ''}` - if (result.status === 0 || !RETRYABLE_NPM.test(failure)) return readNpmView(result, spec, field) + const timedOut = result.error?.code === 'ETIMEDOUT' || result.signal !== null + if (result.status === 0 || (!timedOut && !RETRYABLE_NPM.test(failure))) return readNpmView(result, spec, field) last = new Error(`npm view ${spec} ${field} failed during a registry outage (attempt ${attempt}/4)`) if (attempt < 4) sleepSync(attempt * 3_000) }