Skip to content

Commit b699e5c

Browse files
matheus23Ralith
authored andcommitted
Avoid underflow panic in packet loss Instant calculations
1 parent 4f7f3e7 commit b699e5c

File tree

1 file changed

+5
-4
lines changed
  • quinn-proto/src/connection

1 file changed

+5
-4
lines changed

quinn-proto/src/connection/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,8 +1712,6 @@ impl Connection {
17121712
let rtt = self.path.rtt.conservative();
17131713
let loss_delay = cmp::max(rtt.mul_f32(self.config.time_threshold), TIMER_GRANULARITY);
17141714

1715-
// Packets sent before this time are deemed lost.
1716-
let lost_send_time = now.checked_sub(loss_delay).unwrap();
17171715
let largest_acked_packet = self.spaces[pn_space].largest_acked_packet.unwrap();
17181716
let packet_threshold = self.config.packet_threshold as u64;
17191717
let mut size_of_lost_packets = 0u64;
@@ -1737,8 +1735,11 @@ impl Connection {
17371735
persistent_congestion_start = None;
17381736
}
17391737

1740-
if info.time_sent <= lost_send_time || largest_acked_packet >= packet + packet_threshold
1741-
{
1738+
// Packets sent before now - loss_delay are deemed lost.
1739+
// However, we avoid this subtraction as it can panic and there's no
1740+
// saturating equivalent of this substraction operation with a Duration.
1741+
let packet_too_old = now.saturating_duration_since(info.time_sent) >= loss_delay;
1742+
if packet_too_old || largest_acked_packet >= packet + packet_threshold {
17421743
if Some(packet) == in_flight_mtu_probe {
17431744
// Lost MTU probes are not included in `lost_packets`, because they should not
17441745
// trigger a congestion control response

0 commit comments

Comments
 (0)