Commit 313cf39d authored by Mikio Hara's avatar Mikio Hara Committed by Andrew Gerrand

http2: fix data race on pipe

Fixes golang/go#15999.

Change-Id: I20793ce717c768557c4942ff6be4e77c23ab201c
Reviewed-on: https://go-review.googlesource.com/23880
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
parent 154d9f9e
...@@ -29,6 +29,12 @@ type pipeBuffer interface { ...@@ -29,6 +29,12 @@ type pipeBuffer interface {
io.Reader io.Reader
} }
func (p *pipe) Len() int {
p.mu.Lock()
defer p.mu.Unlock()
return p.b.Len()
}
// Read waits until data is available and copies bytes // Read waits until data is available and copies bytes
// from the buffer into p. // from the buffer into p.
func (p *pipe) Read(d []byte) (n int, err error) { func (p *pipe) Read(d []byte) (n int, err error) {
......
...@@ -1462,7 +1462,7 @@ func (b transportResponseBody) Read(p []byte) (n int, err error) { ...@@ -1462,7 +1462,7 @@ func (b transportResponseBody) Read(p []byte) (n int, err error) {
// Consider any buffered body data (read from the conn but not // Consider any buffered body data (read from the conn but not
// consumed by the client) when computing flow control for this // consumed by the client) when computing flow control for this
// stream. // stream.
v := int(cs.inflow.available()) + cs.bufPipe.b.Len() v := int(cs.inflow.available()) + cs.bufPipe.Len()
if v < transportDefaultStreamFlow-transportDefaultStreamMinRefresh { if v < transportDefaultStreamFlow-transportDefaultStreamMinRefresh {
streamAdd = int32(transportDefaultStreamFlow - v) streamAdd = int32(transportDefaultStreamFlow - v)
cs.inflow.add(streamAdd) cs.inflow.add(streamAdd)
......
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