From 55be92985a2503bfefecf54935fa433279f55674 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Wed, 8 May 2024 13:42:07 -0700 Subject: [PATCH] Fix empty packets when segment size is too small for queued data The prior logic could even produce panics if segment size falls below MIN_PACKET_SPACE. --- quinn-proto/src/connection/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index 72fb48b00..bb0e67e04 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -720,6 +720,20 @@ impl Connection { // Clip the unused capacity out of the buffer so future packets don't // overrun buf_capacity = buf.len(); + + // Check whether the data we planned to send will fit in the reduced segment + // size. If not, bail out and leave it for the next GSO batch so we don't + // end up trying to send an empty packet. We can't easily compute the right + // segment size before the original call to `space_can_send`, because at + // that time we haven't determined whether we're going to coalesce with the + // first datagram or potentially pad it to `MIN_INITIAL_SIZE`. + if space_id == SpaceId::Data { + let frame_space_1rtt = + segment_size.saturating_sub(self.predict_1rtt_overhead(Some(pn))); + if self.space_can_send(space_id, frame_space_1rtt).is_empty() { + break; + } + } } }