From b71aced4a2a1ee80a1cbbd26b85a57623790d7f4 Mon Sep 17 00:00:00 2001 From: lyuxuan Date: Fri, 19 Jan 2018 09:37:59 -0800 Subject: [PATCH] transport: Fix a data race when headers are received while the stream is being closed (#1814) --- transport/http2_client.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/transport/http2_client.go b/transport/http2_client.go index b4495aef..97709069 100644 --- a/transport/http2_client.go +++ b/transport/http2_client.go @@ -1116,12 +1116,13 @@ func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) { }() s.mu.Lock() - if !endStream { - s.recvCompress = state.encoding - } if !s.headerDone { - if !endStream && len(state.mdata) > 0 { - s.header = state.mdata + // Headers frame is not actually a trailers-only frame. + if !endStream { + s.recvCompress = state.encoding + if len(state.mdata) > 0 { + s.header = state.mdata + } } close(s.headerChan) s.headerDone = true