diff --git a/internal/ackhandler/sent_packet_handler.go b/internal/ackhandler/sent_packet_handler.go index dd8988f0f68..c12dc5d9e5d 100644 --- a/internal/ackhandler/sent_packet_handler.go +++ b/internal/ackhandler/sent_packet_handler.go @@ -536,6 +536,13 @@ func (h *sentPacketHandler) setLossDetectionTimer() { // PTO alarm ptoTime, encLevel, ok := h.getPTOTimeAndSpace() if !ok { + if !oldAlarm.IsZero() { + h.alarm = time.Time{} + h.logger.Debugf("Canceling loss detection timer. No PTO needed..") + if h.tracer != nil { + h.tracer.LossTimerCanceled() + } + } return } h.alarm = ptoTime diff --git a/internal/ackhandler/sent_packet_handler_test.go b/internal/ackhandler/sent_packet_handler_test.go index 7282444dedb..dfa760365ab 100644 --- a/internal/ackhandler/sent_packet_handler_test.go +++ b/internal/ackhandler/sent_packet_handler_test.go @@ -931,6 +931,17 @@ var _ = Describe("SentPacketHandler", func() { handler.ReceivedPacket(protocol.EncryptionHandshake) Expect(handler.GetLossDetectionTimeout()).ToNot(BeZero()) }) + + It("cancels the loss detection alarm when all Handshake packets are acknowledged", func() { + t := time.Now().Add(-time.Second) + handler.ReceivedBytes(99999) + handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2, SendTime: t})) + handler.SentPacket(handshakePacket(&Packet{PacketNumber: 3, SendTime: t})) + handler.SentPacket(handshakePacket(&Packet{PacketNumber: 4, SendTime: t})) + Expect(handler.GetLossDetectionTimeout()).ToNot(BeZero()) + handler.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 3, Largest: 4}}}, protocol.EncryptionHandshake, time.Now()) + Expect(handler.GetLossDetectionTimeout()).To(BeZero()) + }) }) Context("amplification limit, for the client", func() {