refactor(core): use global undici timeouts instead of hard request timeouts

This commit is contained in:
Bryan Morgan
2026-02-26 11:49:03 -05:00
parent 2076235bd2
commit 8abf08c974
4 changed files with 20 additions and 7 deletions
@@ -84,7 +84,6 @@ describe('CodeAssistServer', () => {
responseType: 'json',
body: expect.any(String),
signal: undefined,
timeout: 60000,
}),
);
@@ -405,7 +404,6 @@ describe('CodeAssistServer', () => {
'Content-Type': 'application/json',
},
signal: undefined,
timeout: 60000,
}),
);
-2
View File
@@ -305,7 +305,6 @@ export class CodeAssistServer implements ContentGenerator {
responseType: 'json',
body: JSON.stringify(req),
signal,
timeout: 60000,
});
return res.data;
}
@@ -353,7 +352,6 @@ export class CodeAssistServer implements ContentGenerator {
responseType: 'stream',
body: JSON.stringify(req),
signal,
timeout: 60000,
});
return (async function* (): AsyncGenerator<T> {
+1 -1
View File
@@ -206,7 +206,7 @@ export async function createContentGenerator(
'x-gemini-api-privileged-user-id': `${installationId}`,
};
}
const httpOptions = { headers, timeout: 60000 };
const httpOptions = { headers };
const googleGenAI = new GoogleGenAI({
apiKey: config.apiKey === '' ? undefined : config.apiKey,
+19 -2
View File
@@ -6,7 +6,18 @@
import { getErrorMessage, isNodeError } from './errors.js';
import { URL } from 'node:url';
import { ProxyAgent, setGlobalDispatcher } from 'undici';
import { Agent, ProxyAgent, setGlobalDispatcher } from 'undici';
const DEFAULT_HEADERS_TIMEOUT = 60000; // 60 seconds
const DEFAULT_BODY_TIMEOUT = 300000; // 5 minutes
// Configure default global dispatcher with higher timeouts
setGlobalDispatcher(
new Agent({
headersTimeout: DEFAULT_HEADERS_TIMEOUT,
bodyTimeout: DEFAULT_BODY_TIMEOUT,
}),
);
const PRIVATE_IP_RANGES = [
/^10\./,
@@ -73,5 +84,11 @@ export async function fetchWithTimeout(
}
export function setGlobalProxy(proxy: string) {
setGlobalDispatcher(new ProxyAgent(proxy));
setGlobalDispatcher(
new ProxyAgent({
uri: proxy,
headersTimeout: DEFAULT_HEADERS_TIMEOUT,
bodyTimeout: DEFAULT_BODY_TIMEOUT,
}),
);
}