Builds (or reuses) the keep-alive agents for one request's socket bounds.
When the caller leaves maxSockets/maxFreeSockets unset, the shared
module-level agents are reused and the default path allocates nothing.
destroyCachedAgents tears the pair down; the next request rebuilds
it. Supplying either
bound constructs dedicated agents, but identical configurations now share
one cached agent pair (bounded by MAX_CACHED_AGENT_PAIRS) so
repeated requests with the same socket settings reuse warm sockets instead
of leaking a fresh agent pair per request. LRU entries are evicted
(dropped from the cache without destroying their agents, which may still
carry in-flight requests) when the cap is reached.
A defined-but-invalid bound (non-finite, non-integer, or negative) throws a
TypeError, matching the transport's handling of timeout: a typo like
maxSockets: 2.5 is a caller bug that must surface, not silently coerce to
a default.
Parameters
maxSockets: number|undefined
Upper bound on concurrent sockets, when customized.
maxFreeSockets: number|undefined
Upper bound on retained idle sockets, when customized.
Returns {httpAgent:Agent;httpsAgent:Agent}
The agents to send the request with.
Throws
A TypeError when either bound is defined but not a finite,
non-negative integer.
Builds (or reuses) the keep-alive agents for one request's socket bounds.
When the caller leaves
maxSockets/maxFreeSocketsunset, the shared module-level agents are reused and the default path allocates nothing. destroyCachedAgents tears the pair down; the next request rebuilds it. Supplying either bound constructs dedicated agents, but identical configurations now share one cached agent pair (bounded byMAX_CACHED_AGENT_PAIRS) so repeated requests with the same socket settings reuse warm sockets instead of leaking a fresh agent pair per request. LRU entries are evicted (dropped from the cache without destroying their agents, which may still carry in-flight requests) when the cap is reached.A defined-but-invalid bound (non-finite, non-integer, or negative) throws a
TypeError, matching the transport's handling oftimeout: a typo likemaxSockets: 2.5is a caller bug that must surface, not silently coerce to a default.