Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http.server.close() closes idle connections in v20 and v21 #53939

Open
JoMC98 opened this issue Jul 19, 2024 · 3 comments
Open

http.server.close() closes idle connections in v20 and v21 #53939

JoMC98 opened this issue Jul 19, 2024 · 3 comments
Labels
http Issues or PRs related to the http subsystem.

Comments

@JoMC98
Copy link

JoMC98 commented Jul 19, 2024

Version

21.7.3

Platform

No response

Subsystem

No response

What steps will reproduce the bug?

No response

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.

Additional information

No response

@RedYetiDev
Copy link
Member

Can you reproduce on v22?

@RedYetiDev RedYetiDev added the http Issues or PRs related to the http subsystem. label Jul 19, 2024
@JoMC98
Copy link
Author

JoMC98 commented Jul 19, 2024

Can you reproduce on v22?

Yes, in 22.5.1 is also present the same line, that was removed on 18.20.3.

@climba03003
Copy link
Contributor

climba03003 commented 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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants