Set default keepAlive options when creating HTTP/S agents #55770
Labels
feature request
Issues that request new features to be added to Node.js.
https
Issues or PRs related to the https subsystem.
What is the problem this feature will solve?
Since #37184 proposal was accepted, Node's HTTP/S
globalAgent
sets thekeepAlive
option totrue
by default, with a socket timeout of 5 seconds. However, I find this is inconsistent with the observed behavior when using theAgent
constructor, which by default returns an agent withkeepAlive
set tofalse
.What is the feature you are proposing to solve the problem?
Set
keepAlive
to true when creating a new HTTP/S agent, as well as setting the socket timeout to 5 seconds, to equal the behavior of theglobalAgent
. However, I recognize that this change could have unintended effects for users. Additionally, the impact of settingkeepAlive
totrue
in theglobalAgent
is still under discussion (see #47130). So, please, check my alternatives too.What alternatives have you considered?
keepAlive
tofalse
by default, but in case it is provided, set a default socket timeout iftimeout
is not provided. I ran into this problem this week: I was usingkeepAlive
without setting atimeout
value, so sockets were not being closed after inactivity. If the server sends a FIN packet and that event is not processed by the client before sending a new request, anECONNRESET
error will be thrown (as observed in ECONNRESET while doing http 1.1 keep alive requests and server closes the connections #47130). I found that settingtimeout
to 5 seconds, as with theglobalAgent
, greatly reduces the number of errors.timeout
value, at least specify in Node HTTP docs that, if it is not provided by the user, no timeout will be set (and that it could lead to possible errors as described above).Whichever alternative is chosen, I would be more than willing to submit a PR with a solution. Thank you!
@nodejs/http (I don't know if that still works)
The text was updated successfully, but these errors were encountered: