From 9aa262f91495ccbf107ef50a504901599f269a85 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Fri, 16 Jun 2017 15:07:21 -0700 Subject: [PATCH] Protect bytesSent and bytesReceived with mutex to avoid datarace --- transport/http2_client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/transport/http2_client.go b/transport/http2_client.go index 6874a10acc1c..f89045ec08bc 100644 --- a/transport/http2_client.go +++ b/transport/http2_client.go @@ -526,7 +526,9 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea return nil, connectionErrorf(true, err, "transport: %v", err) } } + s.mu.Lock() s.bytesSent = true + s.mu.Unlock() if t.statsHandler != nil { outHeader := &stats.OutHeader{ @@ -1009,7 +1011,9 @@ func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) { if !ok { return } + s.mu.Lock() s.bytesReceived = true + s.mu.Unlock() var state decodeState if err := state.decodeResponseHeader(frame); err != nil { s.mu.Lock()