Skip to content

Commit da87cf5

Browse files
committed
net/http: fix a data race when Request.Cancel is used
The "add a Request.Cancel channel" change (https://golang.org/cl/11601) added support for "race free" cancellation, but introduced a data race. :) Noticed while running "go test -race net/http". The test is skipped in short mode, so we never saw it on the dashboard. Change-Id: Ica14579d8723f8f9d1691e8d56c30b585b332c64 Reviewed-on: https://go-review.googlesource.com/12663 Reviewed-by: Aaron Jacobs <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 56a0624 commit da87cf5

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/net/http/transport.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ func (pc *persistConn) readLoop() {
975975
// the underlying bufio reader.
976976
select {
977977
case <-rc.req.Cancel:
978+
alive = false
978979
pc.t.CancelRequest(rc.req)
979980
case bodyEOF := <-waitForBodyRead:
980981
pc.t.setReqCanceler(rc.req, nil) // before pc might return to idle pool

0 commit comments

Comments
 (0)