mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net/http: fix server/transport data race when sharing the request body
Introduced in https://go-review.googlesource.com/12865 (git revc2db5f4c). This fix doesn't add any new lock acquistions: it just moves the existing one taken by the unreadDataSize method and moves it out wider. It became flaky at revc2db5f4c, but now reliably passes again: $ go test -v -race -run=TestTransportAndServerSharedBodyRace -count=100 net/http Fixes #11985 Change-Id: I6956d62839fd7c37e2f7441b1d425793f4a0db30 Reviewed-on: https://go-review.googlesource.com/12909 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
5e15e28e0e
commit
7aa4e29dce
2 changed files with 6 additions and 5 deletions
|
|
@ -880,17 +880,19 @@ func (cw *chunkWriter) writeHeader(p []byte) {
|
|||
discard = true
|
||||
}
|
||||
case *body:
|
||||
bdy.mu.Lock()
|
||||
switch {
|
||||
case bdy.closed:
|
||||
if !bdy.sawEOF {
|
||||
// Body was closed in handler with non-EOF error.
|
||||
w.closeAfterReply = true
|
||||
}
|
||||
case bdy.unreadDataSize() >= maxPostHandlerReadBytes:
|
||||
case bdy.unreadDataSizeLocked() >= maxPostHandlerReadBytes:
|
||||
tooBig = true
|
||||
default:
|
||||
discard = true
|
||||
}
|
||||
bdy.mu.Unlock()
|
||||
default:
|
||||
discard = true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue