internal: fix context leak when stream is not created successfully #2985

This commit is contained in:
Can Guler 2019-08-19 10:04:28 -07:00 committed by GitHub
parent 451cf373a7
commit 7cc213310c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -359,12 +359,14 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
rstCode: http2.ErrCodeRefusedStream, rstCode: http2.ErrCodeRefusedStream,
onWrite: func() {}, onWrite: func() {},
}) })
s.cancel()
return false return false
} }
} }
t.mu.Lock() t.mu.Lock()
if t.state != reachable { if t.state != reachable {
t.mu.Unlock() t.mu.Unlock()
s.cancel()
return false return false
} }
if uint32(len(t.activeStreams)) >= t.maxStreams { if uint32(len(t.activeStreams)) >= t.maxStreams {
@ -375,12 +377,14 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
rstCode: http2.ErrCodeRefusedStream, rstCode: http2.ErrCodeRefusedStream,
onWrite: func() {}, onWrite: func() {},
}) })
s.cancel()
return false return false
} }
if streamID%2 != 1 || streamID <= t.maxStreamID { if streamID%2 != 1 || streamID <= t.maxStreamID {
t.mu.Unlock() t.mu.Unlock()
// illegal gRPC stream id. // illegal gRPC stream id.
errorf("transport: http2Server.HandleStreams received an illegal stream id: %v", streamID) errorf("transport: http2Server.HandleStreams received an illegal stream id: %v", streamID)
s.cancel()
return true return true
} }
t.maxStreamID = streamID t.maxStreamID = streamID