Commit 10538a8f authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: fix potential for-select spin with closed Context.Done channel

Noticed when investigating a separate issue.

No external bug report or repro yet.

Change-Id: I8a1641a43163f22b09accd3beb25dd9e2a68a238
Reviewed-on: https://go-review.googlesource.com/25152
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAndrew Gerrand <adg@golang.org>
parent 243d51f0
...@@ -1784,6 +1784,7 @@ func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err err ...@@ -1784,6 +1784,7 @@ func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err err
var re responseAndError var re responseAndError
var respHeaderTimer <-chan time.Time var respHeaderTimer <-chan time.Time
cancelChan := req.Request.Cancel cancelChan := req.Request.Cancel
ctxDoneChan := req.Context().Done()
WaitResponse: WaitResponse:
for { for {
testHookWaitResLoop() testHookWaitResLoop()
...@@ -1815,9 +1816,11 @@ WaitResponse: ...@@ -1815,9 +1816,11 @@ WaitResponse:
case <-cancelChan: case <-cancelChan:
pc.t.CancelRequest(req.Request) pc.t.CancelRequest(req.Request)
cancelChan = nil cancelChan = nil
case <-req.Context().Done(): ctxDoneChan = nil
case <-ctxDoneChan:
pc.t.CancelRequest(req.Request) pc.t.CancelRequest(req.Request)
cancelChan = nil cancelChan = nil
ctxDoneChan = nil
} }
} }
......
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