Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions dev-packages/cloudflare-integration-tests/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ export function cleanupChildProcesses(): void {
process.on('exit', cleanupChildProcesses);

// Wrangler can report "Ready" before it can actually handle requests.
// This retries fetch on connection errors to handle this race condition.
// This retries fetch on connection errors and transient 500 responses to handle this race condition.
async function fetchWithRetry(url: string, init: RequestInit, maxRetries = 10, retryDelayMs = 200): Promise<Response> {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
return await fetch(url, init);
const res = await fetch(url, init);

if (res.status === 500 && attempt < maxRetries - 1) {
if (process.env.DEBUG) log(`Got 500, retrying (attempt ${attempt + 1}/${maxRetries})...`);
await new Promise(r => setTimeout(r, retryDelayMs));
continue;
}

return res;
} catch (e) {
const isConnectionError =
e instanceof Error && (e.message.includes('ECONNREFUSED') || e.message.includes('fetch failed'));
Expand Down
Loading