properly handle errors that occur while handling packets in the session

fixes #614
This commit is contained in:
Marten Seemann
2017-05-13 19:14:25 +08:00
parent 222ffa2f48
commit 4fd410700d
2 changed files with 15 additions and 1 deletions

View File

@@ -265,7 +265,7 @@ runLoop:
continue
}
s.close(err)
break runLoop
continue
}
// This is a bit unclean, but works properly, since the packet always
// begins with the public header and we never copy it.

View File

@@ -708,6 +708,20 @@ var _ = Describe("Session", func() {
Expect(sess.largestRcvdPacketNumber).To(Equal(protocol.PacketNumber(5)))
})
It("closes when handling a packet fails", func(done Done) {
testErr := errors.New("unpack error")
hdr.PacketNumber = 5
var runErr error
go func() {
runErr = sess.run()
}()
sess.unpacker.(*mockUnpacker).unpackErr = testErr
sess.handlePacket(&receivedPacket{publicHeader: hdr})
Eventually(func() error { return runErr }).Should(MatchError(testErr))
Expect(sess.runClosed).To(BeClosed())
close(done)
})
It("sets the {last,largest}RcvdPacketNumber, for an out-of-order packet", func() {
hdr.PacketNumber = 5
err := sess.handlePacketImpl(&receivedPacket{publicHeader: hdr})