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
nogoegst opened this issue Dec 7, 2017 · 8 comments
Closed

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

nogoegst opened this issue Dec 7, 2017 · 8 comments
Assignees
Milestone

Comments

@nogoegst
Copy link
Contributor

@nogoegst nogoegst 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

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Dec 8, 2017

@bradfitz bradfitz added this to the Go1.11 milestone Dec 8, 2017
@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz 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.

@nogoegst

This comment has been minimized.

Copy link
Contributor Author

@nogoegst nogoegst 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().

@nogoegst

This comment has been minimized.

Copy link
Contributor Author

@nogoegst nogoegst commented Dec 14, 2017

Should I create a CL?

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Dec 14, 2017

Go for it.

@odeke-em

This comment has been minimized.

Copy link
Member

@odeke-em 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 label Jul 9, 2018
@bradfitz bradfitz self-assigned this Jul 9, 2018
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jul 9, 2018

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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jul 9, 2018

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

@gopherbot gopherbot closed this in 194bbe8 Jul 9, 2018
@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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.