Skip to content

x/net/tcp: shouldn't SetKeepAlive() and SetKeepAlivePeriod() be flagged as deprecated or at least be flagged as conflicting with SetKeepAliveConfig #73401

Closed
@bplessis-swi

Description

@bplessis-swi

Go version

go1.24.1

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/bplessis/.local/bin/'
GOCACHE='/Users/bplessis/.cache/go'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/bplessis/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/rr/d6ybyfkx60z5961g5t_b0x4h0000gn/T/go-build1599168907=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/bplessis/travail/devs/mqttfe/go.mod'
GOMODCACHE='/Users/bplessis/.local/share/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/bplessis/.local/share/go:/Users/bplessis/travail/devs/go/'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.2/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/bplessis/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.2/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Hi,

I had a weird time fighting go default tcp keepalive for a service that is connecting IoT devices to a go-based server.

No amount of SetKeepAlive(false) or SetKeepAlive(300) was doing anything to solve my issue and it's only after quite a lot of failures that i fell upon the https://pkg.go.dev/net#ListenConfig structure definition and the following excerpt:

	// KeepAlive specifies the keep-alive period for network
	// connections accepted by this listener.
	//
	// KeepAlive is ignored if KeepAliveConfig.Enable is true.

This lead me to replacing SetKeepAlive(false) with .SetKeepAliveConfig(net.KeepAliveConfig{Enable: false}) and that started to actually do something.

So given that apparently the default keepalive is set using this new mechanism we shoud mark the old function as deprecated or at least add a big warning of the interaction with SetKeepAliveConfig() in the SetKeepAlive()/SetKeepAlivePeriod() definition ?

What did you see happen?

SetKeepAlive/SetKeepAlivePeriod did not have any effect on the keepalive mechanism and there was no direct documentation on the function definition that helped identify the "conflict" with the KeepAliveConfig structure/settings

What did you expect to see?

SetKeepAlive/SetKeepAlivePeriod doc should include a warning or flag the function as deprecated

Activity

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

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @gopherbot@bplessis-swi@gabyhelp

        Issue actions

          x/net/tcp: shouldn't SetKeepAlive() and SetKeepAlivePeriod() be flagged as deprecated or at least be flagged as conflicting with SetKeepAliveConfig · Issue #73401 · golang/go