From bc3c07372a2c5c8adbd92f6af4a97266fa7e528e Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Mon, 4 Jan 2021 13:39:33 -0800 Subject: [PATCH] Improve robustness to large connection-level flow control --- quinn-proto/src/connection/streams.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/quinn-proto/src/connection/streams.rs b/quinn-proto/src/connection/streams.rs index e08578522..cce20c779 100644 --- a/quinn-proto/src/connection/streams.rs +++ b/quinn-proto/src/connection/streams.rs @@ -291,7 +291,7 @@ impl Streams { self.local_max_data, self.stream_receive_window, )?; - self.data_recvd += new_bytes; + self.data_recvd = self.data_recvd.saturating_add(new_bytes); if !rs.assembler.is_stopped() { self.on_stream_frame(true, stream); @@ -355,7 +355,9 @@ impl Streams { // Update flow control Ok(if bytes_read != final_offset.into() { // bytes_read is always <= end, so this won't underflow. - self.data_recvd += u64::from(final_offset) - end; + self.data_recvd = self + .data_recvd + .saturating_add(u64::from(final_offset) - end); self.add_read_credits(u64::from(final_offset) - bytes_read) } else { ShouldTransmit::new(false)