Skip to content
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

net/http: misleading description of Transport.DisableKeepAlives field #26128

Closed
juhwany opened this issue Jun 29, 2018 · 3 comments
Closed

net/http: misleading description of Transport.DisableKeepAlives field #26128

juhwany opened this issue Jun 29, 2018 · 3 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@juhwany
Copy link

juhwany commented Jun 29, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/hanmail/gospace"
GORACE=""
GOROOT="/data1/hanadmin/go"
GOTOOLDIR="/data1/hanadmin/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build037036632=/tmp/go-build"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

http.Transport struct has DisableKeepAlives field and its description says it's related to TCP connection re-use like TCP Keep-alive.

type Transport struct {
...
	// DisableKeepAlives, if true, prevents re-use of TCP connections
	// between different HTTP requests.
	DisableKeepAlives bool
}

But it's actually related to HTTP Keep-alive not TCP Keep-alive. I've found that if it is set to true, then HTTP request header will have "Connection:Close".

net/http/transport.go around 1997 line.

...
	if pc.t.DisableKeepAlives {
		req.extraHeaders().Set("Connection", "close")
	}
...

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

What did you expect to see?

The description about DisableKeepAlive field should be modified. It could make misunderstanding.

What did you see instead?

@juhwany juhwany changed the title Wrong description related to KeepAlive in http.Transport Wrong description related to KeepAlive in net/http/Transport struct Jun 29, 2018
@ianlancetaylor ianlancetaylor changed the title Wrong description related to KeepAlive in net/http/Transport struct net/http: misleading description of Transport.DisableKeepAlives field Jun 29, 2018
@ianlancetaylor ianlancetaylor added Documentation NeedsFix The path to resolution is known, but the work has not been done. labels Jun 29, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Jun 29, 2018
@ianlancetaylor
Copy link
Contributor

CC @bradfitz

@bradfitz
Copy link
Contributor

There are two types of keep-alives: HTTP keep-alives and TCP keep-alives. HTTP almost always runs on top of TCP, so it's not inaccurate to use "TCP" in the description of HTTP keep-alives. The docs you cite never said "TCP keep-alives". It says:

prevents re-use of TCP connections

I really don't think there's any problem here, but I'll add a sentence.

@gopherbot
Copy link

Change https://golang.org/cl/121616 mentions this issue: net/http: update docs on Transport.DisableKeepAlives

@golang golang locked and limited conversation to collaborators Jun 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants