http.Agent keep-alive pooling maxTotalSockets change in Node.js 18+
0 reputation · 13 Nov 2020, 06:18 UTC
Moving an HTTP client that relies on Node.js http.Agent keep-alive pooling across a Node.js major version boundary raises a configuration decision about socket limits.
The affected feature is keep-alive socket reuse governed by maxSockets per origin and, in newer releases, maxTotalSockets for the default agent. agent.destroy() does not guarantee immediate closure of sockets attached to in-flight requests, and socket.setTimeout emits 'timeout' without destroying the socket, so stalled keep-alive connections can remain open.
With keepAlive disabled, each request can open a new socket, while with keepAlive enabled reuse depends on pool size and idle timeout behavior. The interaction between per-host and total limits is version-sensitive and affects how bursts are handled.
What is the effective concurrent socket cap for the default agent in Node.js 18+ when maxSockets is unspecified? Does keepAlive false prevent socket reuse and increase creation rate under bursts? How does maxTotalSockets interact with per-host maxSockets when multiple hosts share the default agent?