axios and Node http.Agent: Should axios expose maxSockets and keepAlive configuration for high-concurrency workloads?
0 reputation · 12 Jan 2021, 00:11 UTC
Integration boundary
Axios delegates all Node.js HTTP(S) connection handling to the built-in http.Agent (or https.Agent). The agent’s maxSockets and keepAlive settings control how many concurrent connections are opened to a single host and whether sockets are reused across requests.
Goal and constraints
Developers running many simultaneous axios requests to the same origin observe latency spikes that disappear when a custom agent with higher maxSockets and keepAlive:true is supplied. Axios currently offers no direct configuration for these parameters; the only supported path is constructing an agent manually and passing it via httpAgent/httpsAgent. This extra step is undocumented as a core feature, and the default maxSockets value changed from 5 to Infinity between Node 18 and 20, making behavior environment-dependent.
Open questions
- Should axios introduce first-class options such as
maxSocketsandkeepAlivein its request config to surface the agent’s concurrency controls without requiring a custom agent instance? - If such options are added, how should axios reconcile them with an explicitly provided
httpAgent/httpsAgentto avoid surprising overrides? - What migration strategy would prevent breaking existing applications that already supply custom agents while still simplifying the common high-concurrency case?