Skip to content

net: the KeepAlive comment in Dialer is not accurate #73386

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

Open
spacewander opened this issue Apr 15, 2025 · 1 comment
Open

net: the KeepAlive comment in Dialer is not accurate #73386

spacewander opened this issue Apr 15, 2025 · 1 comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@spacewander
Copy link
Contributor

The comment says that KeepAlive specifies the interval:

go/src/net/dial.go

Lines 171 to 181 in 396a48b

// KeepAlive specifies the interval between keep-alive
// probes for an active network connection.
//
// KeepAlive is ignored if KeepAliveConfig.Enable is true.
//
// If zero, keep-alive probes are sent with a default value
// (currently 15 seconds), if supported by the protocol and operating
// system. Network protocols or operating systems that do
// not support keep-alive ignore this field.
// If negative, keep-alive probes are disabled.
KeepAlive time.Duration

In fact, it is used as the idle time:

func newTCPConn(fd *netFD, keepAliveIdle time.Duration, keepAliveCfg KeepAliveConfig, preKeepAliveHook func(*netFD), keepAliveHook func(KeepAliveConfig)) *TCPConn {

The KeepAlive field is passed as the second argument, which means idle instead of the interval. It is equal to the Idle field in the KeepAliveConfig:

type KeepAliveConfig struct {
    // If Enable is true, keep-alive probes are enabled.
    Enable bool

    // Idle is the time that the connection must be idle before
    // the first keep-alive probe is sent.
    // If zero, a default value of 15 seconds is used.
    Idle time.Duration

    // Interval is the time between keep-alive probes.
    // If zero, a default value of 15 seconds is used.
    Interval time.Duration

    // Count is the maximum number of keep-alive probes that
    // can go unanswered before dropping a connection.
    // If zero, a default value of 9 is used.
    Count int
}
@prattmic
Copy link
Member

cc @neild

@prattmic prattmic added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 15, 2025
@prattmic prattmic added this to the Backlog milestone Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants