From: Brad Fitzpatrick Date: Fri, 24 Jul 2015 23:27:07 +0000 (-0700) Subject: net/http: fix a data race when Request.Cancel is used X-Git-Tag: go1.5beta3~77 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=da87cf5dcf342a31c82ff7980bdc076558ff6674;p=gostls13.git 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 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/net/http/transport.go b/src/net/http/transport.go index 41fc6d0e62..41e02fc580 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -975,6 +975,7 @@ func (pc *persistConn) readLoop() { // the underlying bufio reader. select { case <-rc.req.Cancel: + alive = false pc.t.CancelRequest(rc.req) case bodyEOF := <-waitForBodyRead: pc.t.setReqCanceler(rc.req, nil) // before pc might return to idle pool