diff --git a/lib/index.js b/lib/index.js index 92d71fb..02c6386 100644 --- a/lib/index.js +++ b/lib/index.js @@ -195,6 +195,14 @@ async function deadOrAliveInternal(state, url) { let response try { + // Create a manually abortable fetch, + // instead of `AbortSignal.timeout(state.timeout)`. + // This way we only abort slow requests; not the other work. + const controller = new AbortController() + const id = setTimeout(function () { + controller.abort() + }, state.timeout) + response = await fetch(url, { headers: { userAgent: state.userAgent, @@ -207,8 +215,10 @@ async function deadOrAliveInternal(state, url) { }, method: 'GET', redirect: 'manual', - signal: AbortSignal.timeout(state.timeout) + signal: controller.signal }) + + clearTimeout(id) } catch (error) { if (state.retries < state.maxRetries) return retry(state, url)