diff --git a/internal/multiplex/session.go b/internal/multiplex/session.go index 541279a..04198f3 100644 --- a/internal/multiplex/session.go +++ b/internal/multiplex/session.go @@ -195,7 +195,9 @@ func (sesh *Session) closeStream(s *Stream, active bool) error { log.Tracef("stream %v passively closed", s.id) } - // id may or may not exist as this is user input, if we use Delete(s.id) here it will panic + // We set it as nil to signify that the stream id had existed before. + // If we Delete(s.id) straight away, later on in recvDataFromRemote, it will not be able to tell + // if the frame it received was from a new stream or a dying stream whose frame arrived late sesh.streams.Store(s.id, nil) if sesh.streamCountDecr() == 0 { if sesh.Singleplex { diff --git a/internal/multiplex/session_test.go b/internal/multiplex/session_test.go index f2de88c..b40d32c 100644 --- a/internal/multiplex/session_test.go +++ b/internal/multiplex/session_test.go @@ -237,8 +237,9 @@ func TestRecvDataFromRemote_Closing_InOrder(t *testing.T) { if s1I != nil { t.Error("stream 1 exists after receiving stream close for the second time") } - if sesh.streamCount() != 1 { - t.Error("stream count isn't 1 after stream 1 closed twice") + streamCount := sesh.streamCount() + if streamCount != 1 { + t.Errorf("stream count is %v after stream 1 closed twice, expected 1", streamCount) } // close session