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

x/net/http2: missing httptrace.GetConn hook #23041

Closed
unkaktus opened this issue Dec 7, 2017 · 8 comments
Closed

x/net/http2: missing httptrace.GetConn hook #23041

unkaktus opened this issue Dec 7, 2017 · 8 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@unkaktus
Copy link
Contributor

unkaktus commented Dec 7, 2017

http2 implementation does not call GetConn hook before getting connection from pool [1]. As per net/http/httptrace documentation:

GetConn is called even if there's already an idle cached connection available.

For the record, this breaks clients that rely on GetConn->GotConn timings (such as hey benchmark) so they report wrong results.

[1] https://github.com/golang/net/blob/master/http2/transport.go#L353

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.2 openbsd/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="openbsd"
GOOS="openbsd"
GOPATH="/home/gopher/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/openbsd_amd64"
GCCGO="gccgo"
CC="cc"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build311252074=/tmp/go-build -gno-record-gcc-switches"
CXX="c++"
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?

package main

import (
        "context"
        "log"
        "net/http"
        "net/http/httptrace"
)

func main() {
        log.SetFlags(0)
        t := http.DefaultTransport
        for i := 0; i < 3; i++ {
                trace := &httptrace.ClientTrace{
                        GetConn: func(hostport string) {
                                log.Printf("GetConn")
                        },
                        GotConn: func(gci httptrace.GotConnInfo) {
                                log.Printf("GotConn")
                        },
                }
                ctx := httptrace.WithClientTrace(context.Background(), trace)
                r, _ := http.NewRequest("GET", "https://golang.org/", nil)
                _, err := t.RoundTrip(r.WithContext(ctx))
                if err != nil {
                        log.Fatal(err)
                }
        }
}

What did you expect to see?

GetConn
GotConn
GetConn
GotConn
GetConn
GotConn

What did you see instead?

GetConn
GotConn
GotConn
GotConn
@bradfitz
Copy link
Contributor

bradfitz commented Dec 8, 2017

/cc @tombergan

@bradfitz bradfitz added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 8, 2017
@bradfitz bradfitz added this to the Go1.11 milestone Dec 8, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Dec 8, 2017

By default this would be for Go 1.11 if this is a bug (I assume it is), but if it's a trivial fix I wouldn't fight it going into Go 1.10 either.

@unkaktus
Copy link
Contributor Author

unkaktus commented Dec 8, 2017

I guess it's a trivial fix because traceGetConn is simply not implemented.
I've fixed it just by implementing traceGetConn akin traceGotConn and plugging in before connPool().GetClientConn().

@unkaktus
Copy link
Contributor Author

Should I create a CL?

@bradfitz
Copy link
Contributor

Go for it.

@odeke-em
Copy link
Member

odeke-em commented Jul 7, 2018

Gentle ping @nogoegst, as Go1.11 is coming up in less than a month.

@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 9, 2018
@bradfitz bradfitz self-assigned this Jul 9, 2018
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 9, 2018
@gopherbot
Copy link

Change https://golang.org/cl/122590 mentions this issue: http2: call httptrace.ClientTrace.GetConn in Transport when needed

gopherbot pushed a commit to golang/net that referenced this issue Jul 9, 2018
Tests in CL 122591 in the standard library, to be submitted after this
CL.

Updates golang/go#23041

Change-Id: I3538cc7d2a71e3a26ab4c2f47bb220a25404cddb
Reviewed-on: https://go-review.googlesource.com/122590
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/122591 mentions this issue: net/http: update bundled http2

@golang golang locked and limited conversation to collaborators Jul 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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