Compare commits

...

3 Commits

Author SHA1 Message Date
Fallenbagel
46e95317f6 fix(proxy): add connection limits and IPv4 support to undici agents 2026-01-17 07:07:56 +05:00
fallenbagel
b55c49c360 fix(proxy): pass forceIpv4First option to custom proxy agent 2026-01-16 09:39:46 +08:00
fallenbagel
f46773ec8f 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
2026-01-16 09:26:01 +08:00
2 changed files with 23 additions and 8 deletions

View File

@@ -97,7 +97,10 @@ app
// Register HTTP proxy
if (settings.network.proxy.enabled) {
await createCustomProxyAgent(settings.network.proxy);
await createCustomProxyAgent(
settings.network.proxy,
settings.network.forceIpv4First
);
}
// Migrate library types

View File

@@ -11,9 +11,14 @@ export let requestInterceptorFunction: (
) => InternalAxiosRequestConfig;
export default async function createCustomProxyAgent(
proxySettings: ProxySettings
proxySettings: ProxySettings,
forceIpv4First?: boolean
) {
const defaultAgent = new Agent({ keepAliveTimeout: 5000 });
const defaultAgent = new Agent({
keepAliveTimeout: 5000,
connections: 50,
connect: forceIpv4First ? { family: 4 } : undefined,
});
const skipUrl = (url: string | URL) => {
const hostname =
@@ -67,16 +72,23 @@ export default async function createCustomProxyAgent(
uri: proxyUrl,
token,
keepAliveTimeout: 5000,
connections: 50,
connect: forceIpv4First ? { family: 4 } : undefined,
});
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,
family: forceIpv4First ? 4 : undefined,
};
axios.defaults.httpAgent = new HttpProxyAgent(proxyUrl, agentOptions);
axios.defaults.httpsAgent = new HttpsProxyAgent(proxyUrl, agentOptions);
requestInterceptorFunction = (config) => {
const url = config.baseURL