Skip to content

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

Description

@JoMC98

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

Activity

  1. avivkeller commented on Jul 19, 2024

    @avivkeller
    Member

    Can you reproduce on v22?

  2. added
    httpIssues and PRs related to the http subsystem.
    on Jul 19, 2024
  3. JoMC98 commented on Jul 19, 2024

    @JoMC98
    Author

    Can you reproduce on v22?

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

  4. climba03003 commented on Jul 23, 2024

    @climba03003
    Contributor

    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.

  5. bjohansebas commented on May 25, 2025

    @bjohansebas
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues and PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions