镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

net: setKeepAlive options ignored before connect #31663

Description

@lgpasquale
  • Version: v13.7.0
  • Platform: linux 5.5.2
  • Subsystem: net

If setKeepAlive() is called on a tcp socket before the connect event, then the initialDelay parameter is ignored.
This bug was alread reported here for version 0.12, but it still seems to be there in 13.7.

If, for instance, I call setKeepAlive(true, 10000) before the connect event, the default initialDelay of 7200s is used.
netstat -ntp --timers gives:

tcp        0      0 10.10.15.220:56866      10.10.15.148:6666       ESTABLISHED 132820/node          keepalive (7132.09/0/0)

Activity

  1. added
    netIssues and PRs related to the net subsystem.
    on Dec 26, 2020
  2. pmarrapese commented on Jan 28, 2021

    @pmarrapese
    • Version: v14.15.4
    • Platform: Windows [Version 10.0.17763.1637]

    Confirmed this still behaves this way. In this example, Wireshark shows the first keepalive packet going out 60 seconds after the connection is established.

    const net = require('net');
    
    let socket = net.createConnection({
     host: 'localhost',
     port: 31337
    });
    socket.setKeepAlive(true, 1000);
    socket.on('connect', () => {
     console.log('socket is connected');
    });

    Moving the setKeepAlive call into the connect handler causes them to go out every 1s, as intended. If there is no intention to modify this behavior, this should at least be noted in the documentation.

  3. oyyd commented on Jun 30, 2022

    @oyyd
    Contributor

    Looks like this has been solved in #41310.

  4. github-actions commented on Jun 27, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 210 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.

  5. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 27, 2026
  6. github-actions commented on Jul 28, 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

    netIssues and PRs related to the net subsystem.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