transport: Fix a data race when headers are received while the stream is being closed (#1814)

This commit is contained in:
lyuxuan
2018-01-19 09:37:59 -08:00
committed by dfawley
parent 46bef23bc3
commit b71aced4a2

View File

@ -1116,12 +1116,13 @@ func (t *http2Client) operateHeaders(frame *http2.MetaHeadersFrame) {
}() }()
s.mu.Lock() s.mu.Lock()
if !endStream {
s.recvCompress = state.encoding
}
if !s.headerDone { if !s.headerDone {
if !endStream && len(state.mdata) > 0 { // Headers frame is not actually a trailers-only frame.
s.header = state.mdata if !endStream {
s.recvCompress = state.encoding
if len(state.mdata) > 0 {
s.header = state.mdata
}
} }
close(s.headerChan) close(s.headerChan)
s.headerDone = true s.headerDone = true