Skip to content

net: support TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT on newer Windows #65817

@panjf2000

Description

@panjf2000

In CL 542275, the implementation on Windows has a few limitations:

  • TCP_KEEPCNT is not supported.
  • TCP_KEEPIDLE and TCP_KEEPINTVL cannot be set separately, they must be set together.

go/src/net/tcpsock.go

Lines 121 to 127 in ff4e45f

// Note that Windows doesn't support setting the KeepAliveIdle and KeepAliveInterval separately.
// It's recommended to set both Idle and Interval to non-negative values on Windows if you
// intend to customize the TCP keep-alive settings.
// By contrast, if only one of Idle and Interval is set to a non-negative value, the other will
// be set to the system default value, and ultimately, set both Idle and Interval to negative
// values if you want to leave them unchanged.
type KeepAliveConfig struct {

These limitations come from SIO_KEEPALIVE_VALS that is used for TCP keep-alive on Windows in Go currently. It's a relatively old Winsock API for setting up the TCP keep-alive mechanism. I've done some more in-depth research on Windows and realized that we can do more things on some relatively newer versions of Windows using setsockopt and getsockopt.

TCP_KEEPIDLE and TCP_KEEPINTVL are available starting with Windows 10, version 1709. TCP_KEEPCNT is available starting with Windows 10, version 1703. Therefore, we can reconcile the implementation on Windows 10, version 1709 and later versions with the implementations on UNIX's.

Follows up #65809

References

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.OS-Windows

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions