Skip to content

Clarification needed regarding the http/net Server keepAlive options #61850

Description

@dominykas

Affected URL(s)

No response

Description of the problem

Docs for net.createServer and http.createServer say:

keepAlive If set to true, it enables keep-alive functionality on the socket immediately after a new incoming connection is received, similarly on what is done in socket.setKeepAlive(). Default: false.

This is somewhat misleading, because it does not say what happens for the default false - it could be interpreted as "false disables keep-alive functionality" - which, if I understand things correctly, it does not - this flag changes when keep-alive becomes enabled, not if? But I have not figured out what the answer to the "when" is - would be nice if it was documented.


Additionally, the docs for http's server.keepAliveTimeout say:

A value of 0 will disable the keep-alive timeout behavior on incoming connections. A value of 0 makes the HTTP server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.

This is somewhat presumptuous on people knowing what the behavior was 8 years ago, whereby some of the people reading it might not have even known Node.js exists at that point (or they maybe just got old and can't remember anymore...), so describing that behavior explicitly would be nice.

But that aside, the phrasing can probably improved, because without reading it carefully (e.g. by reading it through an LLM lens, don't ask me how I know 😁), one might misinterpret that 0 means that it will disable the "keep-alive" rather than the "timeout". Perhaps it needs to be rephrased along the lines of "A value of 0 will allow keep-alive connections to persist forever." A note on the implications (memory usage? file handle usage?) would also be useful.

Now, I'll admit this is not the area I'm very familiar with, so maybe I'm misreading this entirely?

Happy to work on the improvements with someone guiding with providing details.


On a completely unrelated note - 😍 #59203

Activity

  1. added
    docIssues and PRs related to Node.js documentation.
    on Feb 16, 2026
  2. ankitsyadav commented on Feb 19, 2026

    @ankitsyadav

    I would like to work on clarifying and improving the documentation wording for these options.

  3. added a commit that references this issue on Feb 19, 2026
    20b99ac
  4. yoshigev commented on Mar 4, 2026

    @yoshigev

    Note another confusing issue regarding socket.setKeepAlive() that is reported on #57712.

  5. github-actions commented on Jul 20, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 90 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  6. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 20, 2026
  7. github-actions commented on Aug 21, 2026

    @github-actions
    Contributor

    This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
    If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

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

    docIssues and PRs related to Node.js documentation.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions