mirror of
https://github.com/bitbaum/fleet.git
synced 2026-12-03 23:07:51 +01:00
* fix: keep cross-repo package scans resilient * fix: retry transient read-only GitHub failures * fix: reduce org drift audit API fanout * fix: expose bounded drift audit read errors
22 lines
877 B
JavaScript
22 lines
877 B
JavaScript
const waitSync = milliseconds => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds);
|
|
|
|
function retryable(error) {
|
|
const detail = `${error.stderr ?? ''}\n${error.message ?? ''}`;
|
|
return /HTTP (?:429|5\d\d)|timed out|ECONNRESET/i.test(detail)
|
|
|| /secondary rate limit|abuse detection|temporarily rate limited/i.test(detail);
|
|
}
|
|
|
|
/** Retry only recognizable transient failures from idempotent GitHub reads. */
|
|
export function withGitHubReadRetry(read, { wait = waitSync } = {}) {
|
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
try {
|
|
return read();
|
|
} catch (error) {
|
|
if (attempt === 2 || !retryable(error)) throw error;
|
|
// A secondary limit asks clients to pause. Bounded backoff avoids
|
|
// repeating the burst; auth and permission errors still fail at once.
|
|
wait(attempt === 0 ? 10_000 : 30_000);
|
|
}
|
|
}
|
|
}
|