From f46773ec8f6c88013bcd6ab043bbe9f0494a3c0b Mon Sep 17 00:00:00 2001 From: fallenbagel <98979876+Fallenbagel@users.noreply.github.com> Date: Fri, 16 Jan 2026 09:11:10 +0800 Subject: [PATCH] fix: configure axios proxy agent socket limits to prevent connection leaks Add socket pool configuration to HttpProxyAgent and HttpsProxyAgent to prevent connection leaks. fix #2297 --- server/utils/customProxyAgent.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/server/utils/customProxyAgent.ts b/server/utils/customProxyAgent.ts index 60f8be6e..970edfd5 100644 --- a/server/utils/customProxyAgent.ts +++ b/server/utils/customProxyAgent.ts @@ -71,12 +71,16 @@ export default async function createCustomProxyAgent( setGlobalDispatcher(proxyAgent.compose(noProxyInterceptor)); - axios.defaults.httpAgent = new HttpProxyAgent(proxyUrl, { + const agentOptions = { headers: token ? { 'proxy-authorization': token } : undefined, - }); - axios.defaults.httpsAgent = new HttpsProxyAgent(proxyUrl, { - headers: token ? { 'proxy-authorization': token } : undefined, - }); + keepAlive: true, + maxSockets: 50, + maxFreeSockets: 10, + timeout: 5000, + scheduling: 'lifo' as const, + }; + axios.defaults.httpAgent = new HttpProxyAgent(proxyUrl, agentOptions); + axios.defaults.httpsAgent = new HttpsProxyAgent(proxyUrl, agentOptions); requestInterceptorFunction = (config) => { const url = config.baseURL