Skip to content

net/http: with Transfer-Encoding: chunked, Transport doesn't reuse the tcp connection #15703

Closed
@jerome-laforge

Description

@jerome-laforge
  1. With both below versions:

    • go version go1.6.2 linux/amd64
    • tip devel +b66b97e Mon May 16 15:05:04 2016 +0000,
  2. 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++"
    
  3. With this program https://play.golang.org/p/HHqlKiVR4o

  4. 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

  5. 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 is cr.r.Buffered() returns 0)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions