properly ignore errors in session

ref #170
This commit is contained in:
Lucas Clemente
2016-06-06 15:00:26 +02:00
parent 76f7a7d153
commit 6d58618279
2 changed files with 35 additions and 13 deletions

View File

@@ -165,17 +165,7 @@ func (s *Session) run() {
}
if err != nil {
switch err {
case ackhandler.ErrDuplicateOrOutOfOrderAck:
// Can happen e.g. when packets thought missing arrive late
case errRstStreamOnInvalidStream:
// Can happen when RST_STREAMs arrive early or late (?)
utils.Errorf("Ignoring error in session: %s", err.Error())
case errWindowUpdateOnClosedStream:
// Can happen when we already sent the last StreamFrame with the FinBit, but the client already sent a WindowUpdate for this Stream
default:
s.Close(err)
}
s.Close(err)
}
if err := s.maybeSendPacket(); err != nil {
@@ -240,7 +230,11 @@ func (s *Session) handlePacketImpl(remoteAddr interface{}, hdr *publicHeader, da
s.receivedPacketHandler.ReceivedPacket(hdr.PacketNumber, packet.entropyBit)
for _, ff := range packet.frames {
return s.handleFrames(packet.frames)
}
func (s *Session) handleFrames(fs []frames.Frame) error {
for _, ff := range fs {
var err error
frames.LogFrame(ff, false)
switch frame := ff.(type) {
@@ -264,8 +258,19 @@ func (s *Session) handlePacketImpl(remoteAddr interface{}, hdr *publicHeader, da
default:
return errors.New("Session BUG: unexpected frame type")
}
if err != nil {
return err
switch err {
case ackhandler.ErrDuplicateOrOutOfOrderAck:
// Can happen e.g. when packets thought missing arrive late
case errRstStreamOnInvalidStream:
// Can happen when RST_STREAMs arrive early or late (?)
utils.Errorf("Ignoring error in session: %s", err.Error())
case errWindowUpdateOnClosedStream:
// Can happen when we already sent the last StreamFrame with the FinBit, but the client already sent a WindowUpdate for this Stream
default:
return err
}
}
}
return nil

View File

@@ -705,4 +705,21 @@ var _ = Describe("Session", func() {
}
})
})
Context("ignoring errors", func() {
It("ignores duplicate acks", func() {
session.sentPacketHandler.SentPacket(&ackhandler.Packet{
PacketNumber: 1,
Length: 1,
})
err := session.handleFrames([]frames.Frame{&frames.AckFrame{
LargestObserved: 1,
}})
Expect(err).NotTo(HaveOccurred())
err = session.handleFrames([]frames.Frame{&frames.AckFrame{
LargestObserved: 1,
}})
Expect(err).NotTo(HaveOccurred())
})
})
})