From 50022bfeb5ba7235ddd27a94d5f3fe5f942f940a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 26 Nov 2026 23:41:57 -0800 Subject: [PATCH] fix(quic): charge the keep-alive exempt budget only when a probe reservation is made A keep-alive firing while an earlier exempt probe still waits to leave, as behind a stalled socket, spent another unit of the `hard / (soft / 2)` budget without adding a probe, so the budget could run out before a dead path needed it. Co-Authored-By: Claude Opus 5.5 --- rs/moq-quic/src/connection/mod.rs | 12 +++++++++--- rs/moq-quic/src/tests/keep_alive.rs | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/rs/moq-quic/src/connection/mod.rs b/rs/moq-quic/src/connection/mod.rs index 8ab5e4458e..dbd18658cc 100644 --- a/rs/moq-quic/src/connection/mod.rs +++ b/rs/moq-quic/src/connection/mod.rs @@ -2848,10 +2848,10 @@ impl Connection { .exempt_probes .filter(|&(since, _)| acked < since) .unwrap_or((now, 0)); - if count < limit { + // A reservation still waiting to leave, as behind a stalled socket, already covers this. + if count < limit && self.spaces[space].loss_probes == 0 { self.exempt_probes = Some((since, count + 1)); - let space = &mut self.spaces[space]; - space.loss_probes = space.loss_probes.max(1); + self.spaces[space].loss_probes = 1; } self.timers.set(Timer::KeepAlive, now.saturating_add(after)); } @@ -4652,6 +4652,12 @@ impl Connection { self.prev_path.is_some() } + /// How many keep-alive probes past the congestion window count against the current budget + #[cfg(test)] + pub(crate) fn exempt_probes_spent(&self) -> u32 { + self.exempt_probes.map_or(0, |(_, count)| count) + } + /// Bytes in flight on the current path, and its congestion window #[cfg(test)] pub(crate) fn in_flight_and_window(&self) -> (u64, u64) { diff --git a/rs/moq-quic/src/tests/keep_alive.rs b/rs/moq-quic/src/tests/keep_alive.rs index 4037339812..9d2712d88c 100644 --- a/rs/moq-quic/src/tests/keep_alive.rs +++ b/rs/moq-quic/src/tests/keep_alive.rs @@ -327,6 +327,23 @@ fn unacknowledging_peer_keeps_probes_within_the_window() { assert!(excess <= bound, "{excess} bytes past the window, past {bound}"); } +/// A probe still waiting to leave, as behind a stalled socket, spends the exempt budget once +/// however many times the keep-alive fires before it goes +#[test] +fn unsent_probe_spends_the_budget_once() { + let _guard = subscribe(); + let (mut pair, client_ch, _) = connect(); + pair.drive(); + let until = pair.time.saturating_add(SOFT / 2 * 3 + Duration::from_millis(100)); + let conn = pair.client_conn_mut(client_ch); + // Nothing transmits, so the first probe's reservation stays unsent through three firings. + while let Some(at) = conn.poll_timeout().filter(|&at| at <= until) { + conn.handle_timeout(at); + } + assert!(!conn.is_closed()); + assert_eq!(conn.exempt_probes_spent(), 1); +} + /// Anyone on the path can send a Version Negotiation packet, so one says nothing of the peer and /// leaves a stale session stale #[test]