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

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

Closed
bplessis-swi opened this issue Apr 16, 2025 · 2 comments
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool
Milestone

Comments

@bplessis-swi
Copy link

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

@gopherbot gopherbot added this to the Unreleased milestone Apr 16, 2025
@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Apr 16, 2025
@bplessis-swi
Copy link
Author

Closing after re-testing, sorry assumptions where made due to previous code and i missed something, my root issue was not due to KeepAliveConfig being enabled by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool
Projects
None yet
Development

No branches or pull requests

3 participants