You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
http.server.close() closes idle connections in v20 and v21 #53939
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior? Why is that the expected behavior?
No response
What do you see instead?
In 18.20.3 release notes, it shows:
"This release fixes a regression introduced in Node.js 18.19.0 where http.server.close() was incorrectly closing idle connections."
This fix was made on this pull request in this commit where server.closeIdleConnections(); is removed from httpServerPreClose function.
This was fixed for next 18.x releases, as can be seen here, but on node 20.x and node 21.x, the regression was also included and has not been removed, as can be seen here.
Starting with this release, Node.js sets keepAlive to true by default. This means that any outgoing HTTP(s) connection will automatically use HTTP 1.1 Keep-Alive. The default waiting window is 5 seconds.
Enable keep-alive will deliver better throughput as connections are reused by default.
Additionally, the agent is now able to parse the response Keep-Alive which the servers might send. This header instructs the client on how much to stay connected.
On the other side, the Node.js HTTP server will now automatically disconnect idle clients (which are using HTTP Keep-Alive to reuse the connection) when close() is invoked).
Node.js HTTP(S)/1.1 requests may experience a better throughput/performance by default.
It was accidentally back-ported to v18, so it is a regression only for v18.
Activity
avivkeller commentedon Jul 19, 2024
Can you reproduce on v22?
JoMC98 commentedon Jul 19, 2024
Yes, in 22.5.1 is also present the same line, that was removed on 18.20.3.
climba03003 commentedon Jul 23, 2024
Closing idle connection by default is means to exist starting from
v19.https://github.com/nodejs/node/releases/tag/v19.0.0
It was accidentally back-ported to
v18, so it is a regression only forv18.bjohansebas commentedon May 25, 2025
I'm going to close this because these are the expected changes for Node >=19, but feel free to reopen it if I'm mistaken.