@@ -87,9 +87,9 @@ impl Pacer {
8787 // This is the inverse of the function in `spend`:
8888 // self.t + rtt * (self.p - self.c) / (Self::SPEEDUP * cwnd)
8989 //
90- // The key product is rtt_ns * deficit. `deficit` is at most 2 * MTU
91- // (~3000 bytes for QUIC) . Even a 10-second RTT (10^10 ns) gives
92- // 10^10 * 3000 = 3*10^13, far below u64::MAX (1.8*10^19) .
90+ // `deficit` can exceed 2 × MTU when `self.c` carries accumulated debt
91+ // from consecutive sub-granularity sends . `saturating_mul` caps the
92+ // product safely regardless of the actual value .
9393 let deficit = u64:: try_from ( packet - self . c ) . expect ( "packet is larger than current credit" ) ;
9494 let rtt_ns = u64:: try_from ( rtt. as_nanos ( ) ) . unwrap_or ( u64:: MAX ) ;
9595 let divisor = ( cwnd as u64 ) . saturating_mul ( Self :: SPEEDUP as u64 ) ;
@@ -116,15 +116,15 @@ impl Pacer {
116116 /// 10^8 * 10^10 = 10^18 < `u64::MAX` (1.8*10^19). Beyond that the
117117 /// `saturating_mul` caps the value and callers clamp to `self.m`.
118118 fn bytes_for ( cwnd : usize , rtt : Duration , elapsed : Duration ) -> Option < u64 > {
119- let rtt_ns = u64:: try_from ( rtt. as_nanos ( ) ) . ok ( ) ? ;
119+ let rtt_ns = u64:: try_from ( rtt. as_nanos ( ) ) . unwrap_or ( u64 :: MAX ) ;
120120 let elapsed_ns = u64:: try_from ( elapsed. as_nanos ( ) ) . unwrap_or ( u64:: MAX ) ;
121121 let factor = ( cwnd as u64 ) . saturating_mul ( Self :: SPEEDUP as u64 ) ;
122122 elapsed_ns. saturating_mul ( factor) . checked_div ( rtt_ns)
123123 }
124124
125125 /// Compute the effective pacing rate in bytes per second.
126126 ///
127- /// Returns `None` if `rtt` is zero or the rate exceeds `u64::MAX` .
127+ /// Returns `None` if `rtt` is zero.
128128 pub ( crate ) fn rate ( cwnd : usize , rtt : Duration ) -> Option < u64 > {
129129 Self :: bytes_for ( cwnd, rtt, Duration :: from_secs ( 1 ) )
130130 }
0 commit comments