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: 's avatarIan Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
parent 243d51f0
......@@ -1784,6 +1784,7 @@ func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err err
var re responseAndError
var respHeaderTimer <-chan time.Time
cancelChan := req.Request.Cancel
ctxDoneChan := req.Context().Done()
WaitResponse:
for {
testHookWaitResLoop()
......@@ -1815,9 +1816,11 @@ WaitResponse:
case <-cancelChan:
pc.t.CancelRequest(req.Request)
cancelChan = nil
case <-req.Context().Done():
ctxDoneChan = nil
case <-ctxDoneChan:
pc.t.CancelRequest(req.Request)
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