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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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,
});
};