From 987e31381b12819a6d7843a37af9f4693b790787 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Mon, 19 Jun 2017 13:57:38 -0700 Subject: [PATCH] Protect bytesSent and bytesReceived with mutex to avoid datarace (#1318) --- transport/http2_client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/transport/http2_client.go b/transport/http2_client.go index 52c9610fbead..a762e5562f16 100644 --- a/transport/http2_client.go +++ b/transport/http2_client.go @@ -541,7 +541,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{ @@ -1024,7 +1026,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()