fix: add timeout to fetch to prevent silent hangs (#883)

Add `AbortSignal.timeout(5s)` to fetch requests to ensure they fail fast
instead of hanging indefinitely when network issues occur.
This commit is contained in:
eifinger-bot
2026-05-31 09:37:59 +02:00
committed by GitHub
parent e7108c6ccc
commit 8dc20b2aca
3 changed files with 31 additions and 10 deletions

View File

@@ -14,8 +14,17 @@ export function getProxyAgent() {
return undefined;
}
export const fetch = async (url: string, opts: RequestInit) =>
await undiciFetch(url, {
export const fetch = async (url: string, opts: RequestInit) => {
// Merge timeout signal with any existing signal from opts
const timeoutSignal = AbortSignal.timeout(5_000);
const existingSignal = opts.signal;
const mergedSignal = existingSignal
? AbortSignal.any([timeoutSignal, existingSignal])
: timeoutSignal;
return await undiciFetch(url, {
dispatcher: getProxyAgent(),
...opts,
signal: mergedSignal,
});
};