Skip to content

Commit a3b6e77

Browse files
neildgopherbot
authored andcommitted
quic: don't re-lose packets when discarding keys
When discarding keys for a packet number space, we remove any in-flight packets in that space from our count of bytes in flight. Skip any packets in the space that were already acked or declared lost. Also skip over acked/lost packets when discarding state in response to a Reset message. This change shouldn't have any effect, since we never declare packets acked/lost until we receive an ACK, and we never handle a Reset after receiving an ACK. Change-Id: I8842f03aa06e57a834a211f1284a48fe5d469db3 Reviewed-on: https://go-review.googlesource.com/c/net/+/664335 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> Auto-Submit: Damien Neil <[email protected]>
1 parent 22500a6 commit a3b6e77

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

quic/loss.go

+8
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ func (c *lossState) receiveAckEnd(now time.Time, log *slog.Logger, space numberS
315315
func (c *lossState) discardPackets(space numberSpace, log *slog.Logger, lossf func(numberSpace, *sentPacket, packetFate)) {
316316
for i := 0; i < c.spaces[space].size; i++ {
317317
sent := c.spaces[space].nth(i)
318+
if sent.acked || sent.lost {
319+
// This should not be possible, since we only discard packets
320+
// in spaces which have never received an ack, but check anyway.
321+
continue
322+
}
318323
sent.lost = true
319324
c.cc.packetDiscarded(sent)
320325
lossf(numberSpace(space), sent, packetLost)
@@ -330,6 +335,9 @@ func (c *lossState) discardKeys(now time.Time, log *slog.Logger, space numberSpa
330335
// https://www.rfc-editor.org/rfc/rfc9002.html#section-6.4
331336
for i := 0; i < c.spaces[space].size; i++ {
332337
sent := c.spaces[space].nth(i)
338+
if sent.acked || sent.lost {
339+
continue
340+
}
333341
c.cc.packetDiscarded(sent)
334342
}
335343
c.spaces[space].discard()

quic/loss_test.go

+31-2
Original file line numberDiff line numberDiff line change
@@ -795,16 +795,38 @@ func TestLossKeysDiscarded(t *testing.T) {
795795
// https://www.rfc-editor.org/rfc/rfc9002.html#section-6.4-1
796796
test := newLossTest(t, clientSide, lossTestOpts{})
797797
test.send(initialSpace, 0, testSentPacketSize(1200))
798+
test.send(initialSpace, 1, testSentPacketSize(1200)) // will be acked
799+
test.send(initialSpace, 2, testSentPacketSize(1200))
800+
test.ack(initialSpace, 0*time.Millisecond, i64range[packetNumber]{1, 2})
801+
test.wantAck(initialSpace, 1)
798802
test.send(handshakeSpace, 0, testSentPacketSize(600))
799-
test.wantVar("bytes_in_flight", 1800)
803+
test.send(handshakeSpace, 1, testSentPacketSize(600)) // will be acked
804+
test.send(handshakeSpace, 2, testSentPacketSize(600))
805+
test.ack(handshakeSpace, 0*time.Millisecond, i64range[packetNumber]{1, 2})
806+
test.wantAck(handshakeSpace, 1)
807+
test.wantVar("bytes_in_flight", 1200+1200+600+600) // 3600
800808

801809
test.discardKeys(initialSpace)
802-
test.wantVar("bytes_in_flight", 600)
810+
test.wantVar("bytes_in_flight", 600+600) // 1200
803811

804812
test.discardKeys(handshakeSpace)
805813
test.wantVar("bytes_in_flight", 0)
806814
}
807815

816+
func TestLossDiscardPackets(t *testing.T) {
817+
test := newLossTest(t, clientSide, lossTestOpts{})
818+
test.send(initialSpace, 0, testSentPacketSize(1200))
819+
test.send(initialSpace, 1, testSentPacketSize(1200)) // will be acked
820+
test.send(initialSpace, 2, testSentPacketSize(1200))
821+
test.ack(initialSpace, 0*time.Millisecond, i64range[packetNumber]{1, 2})
822+
test.wantAck(initialSpace, 1)
823+
824+
test.discardPackets(initialSpace)
825+
test.wantLoss(initialSpace, 0)
826+
test.wantLoss(initialSpace, 2)
827+
test.wantVar("bytes_in_flight", 0)
828+
}
829+
808830
func TestLossInitialCongestionWindow(t *testing.T) {
809831
// "Endpoints SHOULD use an initial congestion window of [...]"
810832
// https://www.rfc-editor.org/rfc/rfc9002.html#section-7.2-1
@@ -1492,6 +1514,13 @@ func (c *lossTest) discardKeys(spaceID numberSpace) {
14921514
c.c.discardKeys(c.now, nil, spaceID)
14931515
}
14941516

1517+
func (c *lossTest) discardPackets(spaceID numberSpace) {
1518+
c.t.Helper()
1519+
c.checkUnexpectedEvents()
1520+
c.t.Logf("discard packets in %s", spaceID)
1521+
c.c.discardPackets(spaceID, nil, c.onAckOrLoss)
1522+
}
1523+
14951524
func (c *lossTest) setMaxAckDelay(d time.Duration) {
14961525
c.t.Helper()
14971526
c.checkUnexpectedEvents()

0 commit comments

Comments
 (0)