Skip to content

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

@spacewander

Description

@spacewander

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions