1
0
mirror of https://github.com/golang/go synced 2024-10-01 13:18:33 -06:00

net/http: fix HTTP/2 idle pool tracing

CL 140357 caused HTTP/2 connections to be put in the idle pool, but
failed to properly guard the trace.GotConn call in getConn. dialConn
returns a minimal persistConn with conn == nil for HTTP/2 connections.
This persistConn was then returned from queueForIdleConn and caused the
httptrace.GotConnInfo passed into GotConn to have a nil Conn field.

HTTP/2 connections call GotConn themselves so leave it for HTTP/2 to call
GotConn as is done below.
This commit is contained in:
Tom Thorogood 2019-09-13 20:02:13 +09:30 committed by Tom Thorogood
parent 79877e5f91
commit 7e1634c65c
No known key found for this signature in database
GPG Key ID: 86C63CDA416C6D2F

View File

@ -1195,7 +1195,9 @@ func (t *Transport) getConn(treq *transportRequest, cm connectMethod) (pc *persi
// Queue for idle connection.
if delivered := t.queueForIdleConn(w); delivered {
pc := w.pc
if trace != nil && trace.GotConn != nil {
// Trace only for HTTP/1.
// HTTP/2 calls trace.GotConn itself.
if w.pc.alt == nil && trace != nil && trace.GotConn != nil {
trace.GotConn(pc.gotIdleConnTrace(pc.idleAt))
}
// set request canceler to some non-nil function so we