remove queued StreamFrames when a Stream is closed with an error

fixes #149
This commit is contained in:
Marten Seemann
2016-06-10 19:18:51 +07:00
parent b1c27b5eca
commit 1c1101de0e
2 changed files with 41 additions and 4 deletions

View File

@@ -364,7 +364,7 @@ func (s *Session) handleRstStreamFrame(frame *frames.RstStreamFrame) error {
if !streamExists || str == nil {
return errRstStreamOnInvalidStream
}
str.RegisterError(fmt.Errorf("RST_STREAM received with code %d", frame.ErrorCode))
s.closeStreamWithError(str, fmt.Errorf("RST_STREAM received with code %d", frame.ErrorCode))
return nil
}
@@ -409,14 +409,19 @@ func (s *Session) closeImpl(e error, remoteClose bool) error {
func (s *Session) closeStreamsWithError(err error) {
s.streamsMutex.Lock()
defer s.streamsMutex.Unlock()
for _, s := range s.streams {
if s == nil {
for _, str := range s.streams {
if str == nil {
continue
}
s.RegisterError(err)
s.closeStreamWithError(str, err)
}
}
func (s *Session) closeStreamWithError(str *stream, err error) {
s.streamFrameQueue.RemoveStream(str.StreamID())
str.RegisterError(err)
}
// TODO: try sending more than one packet
func (s *Session) maybeSendPacket() error {
if !s.smallPacketDelayedOccurranceTime.IsZero() && time.Now().Sub(s.smallPacketDelayedOccurranceTime) > protocol.SmallPacketSendDelay {