-
Notifications
You must be signed in to change notification settings - Fork 602
Fix BBR SendAllowance calculation overflow and unit conversion #5236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Hey, this should be a simple type elevation. |
No, your understanding is wrong. Just elevate the type of SendAllowance to 64 bit. |
Co-authored-by: csujedihy <[email protected]>
Co-authored-by: csujedihy <[email protected]>
You're absolutely right. I've implemented the type elevation approach - changed SendAllowance from uint32_t to uint64_t to prevent overflow, rather than changing the formula. Much simpler and cleaner solution. (7fc830d)
Thanks for the clarification! I've implemented the type elevation approach you suggested - the SendAllowance variable is now uint64_t with overflow protection capping at UINT32_MAX. This preserves the original mathematical intent while preventing overflow. (7fc830d) |
Actually, your first iteration makes sense.
|
Basically, wherever allowance is stored, it needs to be 64 bit wide. |
…pe elevation Co-authored-by: csujedihy <[email protected]>
You're absolutely right! I've implemented the comprehensive solution you suggested - restored the unit conversion from the first iteration AND changed SendAllowance types throughout the system. The fix now properly converts units (time and bits to bytes) while using uint64_t types in congestion control interfaces, packet builder, and path structures to prevent overflow. (c56940d) |
…nt64_t Co-authored-by: csujedihy <[email protected]>
Completed - all allowance storage is now 64-bit wide throughout the system. Fixed the final CUBIC |
Problem
The BBR congestion control algorithm's
BbrCongestionControlGetSendAllowance
function had incorrect unit conversion that caused integer overflow at high bandwidth scenarios (6+ Gbps), severely limiting throughput.Root Cause
The calculation was missing two critical unit conversions:
Before (broken):
This formula has dimensional issues:
BandwidthEst
: bits per secondTimeSinceLastSend
: microseconds(bits/sec × microseconds)
without proper unit conversionIssue manifestation:
Solution
Added proper unit conversions following the pattern used elsewhere in BBR code:
After (fixed):
This correctly converts:
/kMicroSecsInSec
- Convert time from microseconds to seconds/BW_UNIT
- Convert bits to bytesVerification
Added unit test demonstrating the fix:
The corrected calculation produces ~2.16 MB for 6 Gbps over 1ms with pacing gain, which is mathematically correct:
(6×10⁹ × 2.885 × 0.001) / 8 ≈ 2.16×10⁶ bytes
.Changes
src/core/bbr.c
(lines 656, 659)Fixes #4889.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.