Skip to content

Commit

Permalink
move s.cancel and remove TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
idiamond-stripe committed Apr 7, 2022
1 parent f739f9e commit 32d8958
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions internal/transport/http2_server.go
Expand Up @@ -1080,7 +1080,6 @@ func (t *http2Server) Write(s *Stream, hdr []byte, data []byte, opts *Options) e
} else {
// Writing headers checks for this condition.
if s.getState() == streamDone {
// TODO(mmukhi, dfawley): Should the server write also return io.EOF?
return t.streamContextErr(s)
}
}
Expand Down Expand Up @@ -1227,10 +1226,6 @@ func (t *http2Server) Close() {

// deleteStream deletes the stream s from transport's active streams.
func (t *http2Server) deleteStream(s *Stream, eosReceived bool) {
// In case stream sending and receiving are invoked in separate
// goroutines (e.g., bi-directional streaming), cancel needs to be
// called to interrupt the potential blocking on other goroutines.
s.cancel()

t.mu.Lock()
if _, ok := t.activeStreams[s.id]; ok {
Expand All @@ -1252,6 +1247,9 @@ func (t *http2Server) deleteStream(s *Stream, eosReceived bool) {

// finishStream closes the stream and puts the trailing headerFrame into controlbuf.
func (t *http2Server) finishStream(s *Stream, rst bool, rstCode http2.ErrCode, hdr *headerFrame, eosReceived bool) {
// In case stream sending and receiving are invoked in separate
// goroutines (e.g., bi-directional streaming), cancel needs to be
// called to interrupt the potential blocking on other goroutines.
s.cancel()

oldState := s.swapState(streamDone)
Expand All @@ -1273,6 +1271,11 @@ func (t *http2Server) finishStream(s *Stream, rst bool, rstCode http2.ErrCode, h

// closeStream clears the footprint of a stream when the stream is not needed any more.
func (t *http2Server) closeStream(s *Stream, rst bool, rstCode http2.ErrCode, eosReceived bool) {
// In case stream sending and receiving are invoked in separate
// goroutines (e.g., bi-directional streaming), cancel needs to be
// called to interrupt the potential blocking on other goroutines.
s.cancel()

s.swapState(streamDone)
t.deleteStream(s, eosReceived)

Expand Down

0 comments on commit 32d8958

Please sign in to comment.