diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2015-08-03 10:04:42 +0200 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2015-08-03 16:06:17 +0000 |
| commit | 7aa4e29dce2b941644ff1f19e528ccc4790c519e (patch) | |
| tree | 27c98c6c3ea85ec4b04fd3e7c5c2563264c99357 /src/net/http/transfer.go | |
| parent | 5e15e28e0ed0c70a9c97310d3a7b408cae8f2e23 (diff) | |
| download | go-7aa4e29dce2b941644ff1f19e528ccc4790c519e.tar.xz | |
net/http: fix server/transport data race when sharing the request body
Introduced in https://go-review.googlesource.com/12865 (git rev c2db5f4c).
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 rev c2db5f4c, 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>
Diffstat (limited to 'src/net/http/transfer.go')
| -rw-r--r-- | src/net/http/transfer.go | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/net/http/transfer.go b/src/net/http/transfer.go index d1762ebbd2..c128a1d3cd 100644 --- a/src/net/http/transfer.go +++ b/src/net/http/transfer.go @@ -737,11 +737,10 @@ func mergeSetHeader(dst *Header, src Header) { } } -// unreadDataSize returns the number of bytes of unread input. +// unreadDataSizeLocked returns the number of bytes of unread input. // It returns -1 if unknown. -func (b *body) unreadDataSize() int64 { - b.mu.Lock() - defer b.mu.Unlock() +// b.mu must be held. +func (b *body) unreadDataSizeLocked() int64 { if lr, ok := b.src.(*io.LimitedReader); ok { return lr.N } |
