From dc1dd06ebee1d4e0c0160af39926897f2db8d8af Mon Sep 17 00:00:00 2001 From: iamqizhao Date: Fri, 6 May 2016 12:01:14 -0700 Subject: [PATCH] Fix a race of onRead couting --- transport/http2_client.go | 5 +++++ transport/http2_server.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/transport/http2_client.go b/transport/http2_client.go index 8e916b00..8082fdc8 100644 --- a/transport/http2_client.go +++ b/transport/http2_client.go @@ -579,6 +579,11 @@ func (t *http2Client) getStream(f http2.Frame) (*Stream, bool) { // Window updates will deliver to the controller for sending when // the cumulative quota exceeds the corresponding threshold. func (t *http2Client) updateWindow(s *Stream, n uint32) { + s.mu.Lock() + defer s.mu.Unlock() + if s.state == streamDone { + return + } if w := t.fc.onRead(n); w > 0 { t.controlBuf.put(&windowUpdate{0, w}) } diff --git a/transport/http2_server.go b/transport/http2_server.go index 6f233d9d..21b63116 100644 --- a/transport/http2_server.go +++ b/transport/http2_server.go @@ -303,6 +303,11 @@ func (t *http2Server) getStream(f http2.Frame) (*Stream, bool) { // Window updates will deliver to the controller for sending when // the cumulative quota exceeds the corresponding threshold. func (t *http2Server) updateWindow(s *Stream, n uint32) { + s.mu.Lock() + defer s.mu.Unlock() + if s.state == streamDone { + return + } if w := t.fc.onRead(n); w > 0 { t.controlBuf.put(&windowUpdate{0, w}) }