Commit 01b86400 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: update bundled http2, pass through Transport.CloseIdleConnections

Wire up Transport.CloseIdleConnections to http2.Transport.CloseIdleConnections.

Updates x/net/http2 to git rev c92cdcb0 for https://golang.org/cl/18678

Fixes #13975

Change-Id: I1183a31256104ff95ae7621e5788cfeee741b1aa
Reviewed-on: https://go-review.googlesource.com/18679Reviewed-by: default avatarAndrew Gerrand <adg@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b05f18e3
...@@ -246,11 +246,11 @@ func http2filterOutClientConn(in []*http2ClientConn, exclude *http2ClientConn) [ ...@@ -246,11 +246,11 @@ func http2filterOutClientConn(in []*http2ClientConn, exclude *http2ClientConn) [
return out return out
} }
func http2configureTransport(t1 *Transport) error { func http2configureTransport(t1 *Transport) (*http2Transport, error) {
connPool := new(http2clientConnPool) connPool := new(http2clientConnPool)
t2 := &http2Transport{ConnPool: http2noDialClientConnPool{connPool}} t2 := &http2Transport{ConnPool: http2noDialClientConnPool{connPool}}
if err := http2registerHTTPSProtocol(t1, http2noDialH2RoundTripper{t2}); err != nil { if err := http2registerHTTPSProtocol(t1, http2noDialH2RoundTripper{t2}); err != nil {
return err return nil, err
} }
if t1.TLSClientConfig == nil { if t1.TLSClientConfig == nil {
t1.TLSClientConfig = new(tls.Config) t1.TLSClientConfig = new(tls.Config)
...@@ -279,7 +279,7 @@ func http2configureTransport(t1 *Transport) error { ...@@ -279,7 +279,7 @@ func http2configureTransport(t1 *Transport) error {
} else { } else {
m["h2"] = upgradeFn m["h2"] = upgradeFn
} }
return nil return t2, nil
} }
// registerHTTPSProtocol calls Transport.RegisterProtocol but // registerHTTPSProtocol calls Transport.RegisterProtocol but
...@@ -4348,7 +4348,8 @@ var http2errTransportVersion = errors.New("http2: ConfigureTransport is only sup ...@@ -4348,7 +4348,8 @@ var http2errTransportVersion = errors.New("http2: ConfigureTransport is only sup
// It requires Go 1.6 or later and returns an error if the net/http package is too old // It requires Go 1.6 or later and returns an error if the net/http package is too old
// or if t1 has already been HTTP/2-enabled. // or if t1 has already been HTTP/2-enabled.
func http2ConfigureTransport(t1 *Transport) error { func http2ConfigureTransport(t1 *Transport) error {
return http2configureTransport(t1) _, err := http2configureTransport(t1)
return err
} }
func (t *http2Transport) connPool() http2ClientConnPool { func (t *http2Transport) connPool() http2ClientConnPool {
......
...@@ -142,10 +142,14 @@ type Transport struct { ...@@ -142,10 +142,14 @@ type Transport struct {
// If TLSNextProto is nil, HTTP/2 support is enabled automatically. // If TLSNextProto is nil, HTTP/2 support is enabled automatically.
TLSNextProto map[string]func(authority string, c *tls.Conn) RoundTripper TLSNextProto map[string]func(authority string, c *tls.Conn) RoundTripper
nextProtoOnce sync.Once // guards initialization of TLSNextProto (onceSetNextProtoDefaults) // nextProtoOnce guards initialization of TLSNextProto and
// h2transport (via onceSetNextProtoDefaults)
nextProtoOnce sync.Once
h2transport *http2Transport // non-nil if http2 wired up
// TODO: tunable on global max cached connections // TODO: tunable on global max cached connections
// TODO: tunable on timeout on cached connections // TODO: tunable on timeout on cached connections
// TODO: tunable on max per-host TCP dials in flight (Issue 13957)
} }
// onceSetNextProtoDefaults initializes TLSNextProto. // onceSetNextProtoDefaults initializes TLSNextProto.
...@@ -157,9 +161,11 @@ func (t *Transport) onceSetNextProtoDefaults() { ...@@ -157,9 +161,11 @@ func (t *Transport) onceSetNextProtoDefaults() {
if t.TLSNextProto != nil { if t.TLSNextProto != nil {
return return
} }
err := http2ConfigureTransport(t) t2, err := http2configureTransport(t)
if err != nil { if err != nil {
log.Printf("Error enabling Transport HTTP/2 support: %v", err) log.Printf("Error enabling Transport HTTP/2 support: %v", err)
} else {
t.h2transport = t2
} }
} }
...@@ -367,6 +373,7 @@ func (t *Transport) RegisterProtocol(scheme string, rt RoundTripper) { ...@@ -367,6 +373,7 @@ func (t *Transport) RegisterProtocol(scheme string, rt RoundTripper) {
// a "keep-alive" state. It does not interrupt any connections currently // a "keep-alive" state. It does not interrupt any connections currently
// in use. // in use.
func (t *Transport) CloseIdleConnections() { func (t *Transport) CloseIdleConnections() {
t.nextProtoOnce.Do(t.onceSetNextProtoDefaults)
t.idleMu.Lock() t.idleMu.Lock()
m := t.idleConn m := t.idleConn
t.idleConn = nil t.idleConn = nil
...@@ -378,6 +385,9 @@ func (t *Transport) CloseIdleConnections() { ...@@ -378,6 +385,9 @@ func (t *Transport) CloseIdleConnections() {
pconn.close(errCloseIdleConns) pconn.close(errCloseIdleConns)
} }
} }
if t2 := t.h2transport; t2 != nil {
t2.CloseIdleConnections()
}
} }
// CancelRequest cancels an in-flight request by closing its connection. // CancelRequest cancels an in-flight request by closing its connection.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment