diff --git a/src/shared/worker-utils.ts b/src/shared/worker-utils.ts index e83b7b4b..a8b77fca 100644 --- a/src/shared/worker-utils.ts +++ b/src/shared/worker-utils.ts @@ -17,16 +17,16 @@ const HEALTH_CHECK_TIMEOUT_MS = getTimeout(HOOK_TIMEOUTS.HEALTH_CHECK); * The orphaned fetch is harmless since the process exits shortly after. */ export function fetchWithTimeout(url: string, init: RequestInit = {}, timeoutMs: number): Promise { - let timeoutId: ReturnType; - return Promise.race([ - fetch(url, init).then(response => { - clearTimeout(timeoutId); - return response; - }), - new Promise((_, reject) => { - timeoutId = setTimeout(() => reject(new Error(`Request timed out after ${timeoutMs}ms`)), timeoutMs); - }), - ]); + return new Promise((resolve, reject) => { + const timeoutId = setTimeout( + () => reject(new Error(`Request timed out after ${timeoutMs}ms`)), + timeoutMs + ); + fetch(url, init).then( + response => { clearTimeout(timeoutId); resolve(response); }, + err => { clearTimeout(timeoutId); reject(err); } + ); + }); } // Cache to avoid repeated settings file reads