aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/net/http/transport.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/net/http/transport.go b/src/net/http/transport.go
index 43b20f2da2..f7904b4a89 100644
--- a/src/net/http/transport.go
+++ b/src/net/http/transport.go
@@ -845,10 +845,26 @@ func (t *Transport) getConn(treq *transportRequest, cm connectMethod) (*persistC
select {
case v := <-dialc:
// Our dial finished.
- if trace != nil && trace.GotConn != nil && v.pc != nil && v.pc.alt == nil {
- trace.GotConn(httptrace.GotConnInfo{Conn: v.pc.conn})
+ if v.pc != nil {
+ if trace != nil && trace.GotConn != nil && v.pc.alt == nil {
+ trace.GotConn(httptrace.GotConnInfo{Conn: v.pc.conn})
+ }
+ return v.pc, nil
}
- return v.pc, v.err
+ // Our dial failed. See why to return a nicer error
+ // value.
+ select {
+ case <-req.Cancel:
+ case <-req.Context().Done():
+ case <-cancelc:
+ default:
+ // It wasn't an error due to cancelation, so
+ // return the original error message:
+ return nil, v.err
+ }
+ // It was an error due to cancelation, so prioritize that
+ // error value. (Issue 16049)
+ return nil, errRequestCanceledConn
case pc := <-idleConnCh:
// Another request finished first and its net.Conn
// became available before our dial. Or somebody