Skip to content

Commit d6d3310

Browse files
committed
fix(release): retry rate-limited HEADs in the download gate
1 parent 9dc15d0 commit d6d3310

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎scripts/release/cdn-consistency.mjs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ export function collectReleaseDownloadUrls({ latestJson, releaseManifest, releas
137137
}
138138

139139
/**
140-
* HEAD each URL and return the ones that do not answer 2xx. A transport error
141-
* or 5xx is retried `attempts` times in total; a 4xx is final at once.
140+
* HEAD each URL and return the ones that do not answer 2xx. A transport error,
141+
* 5xx, 403 or 429 (GitHub rate limiting) is retried `attempts` times in total;
142+
* any other 4xx is final at once.
142143
*/
143144
export async function findUnreachableUrls({ fetchImpl, sleep, urls, attempts = 3, retryDelayMs = 5_000 }) {
144145
const unreachable = [];
@@ -148,7 +149,7 @@ export async function findUnreachableUrls({ fetchImpl, sleep, urls, attempts = 3
148149
try {
149150
const response = await fetchImpl(url, { method: 'HEAD' });
150151
status = response.status;
151-
if (response.ok || (status >= 400 && status < 500)) break;
152+
if (response.ok || (status >= 400 && status < 500 && status !== 403 && status !== 429)) break;
152153
} catch (error) {
153154
status = error instanceof Error ? error.message : 'unreachable';
154155
}

‎scripts/release/cdn-consistency.test.mjs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,17 @@ void test('recovers when a retry succeeds', async () => {
8686
assert.deepEqual(unreachable, []);
8787
assert.equal(calls, 2);
8888
});
89+
90+
void test('retries a rate-limited 429 instead of reporting it at once', async () => {
91+
let calls = 0;
92+
const unreachable = await findUnreachableUrls({
93+
fetchImpl: async () => {
94+
calls += 1;
95+
return new Response(null, { status: calls === 1 ? 429 : 200 });
96+
},
97+
sleep: async () => {},
98+
urls: ['a'],
99+
});
100+
assert.deepEqual(unreachable, []);
101+
assert.equal(calls, 2);
102+
});

0 commit comments

Comments
 (0)