Description
-
With both below versions:
go version go1.6.2 linux/amd64
- tip
devel +b66b97e Mon May 16 15:05:04 2016 +0000
,
-
On Arch Linux, go env:
GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/jerome/go" GORACE="" GOROOT="/usr/lib/go" GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64" GO15VENDOREXPERIMENT="1" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0" CXX="g++"
-
With this program https://play.golang.org/p/HHqlKiVR4o
-
I expect that http client reuses the tcp connection for first and second http request.
The problem is describe more deeply here:
Example : Ensure that http connection will be re-use go-kit/kit#249 -
Sometime, the http client doesn't reuse the tcp connection between first and second http request (I check it with Wireshark filter on port given into the log e.g. tcp.port == 35068).
When the tcp connection is not reused, delve shows me that (https://github.com/golang/go/blob/master/src/net/http/internal/chunked.go#L61)
cr.r.Buffered()
return 0, and EOF isn't read (https://github.com/golang/go/blob/master/src/net/http/internal/chunked.go#L56), as the last 0 that indicates the end of chunked response isn't read.
So http client send a tcp reset to http server and open a new tcp connection.If I drain the response.Body (with
io.Copy(ioutil.Discard, resp.Body)
), the tcp connection is always reused by the http client (even iscr.r.Buffered()
returns 0)