Skip to content

congestion: avoid overflows when calculating pacer budget#5390

Merged
marten-seemann merged 3 commits intomasterfrom
pacer-overflows
Oct 17, 2025
Merged

congestion: avoid overflows when calculating pacer budget#5390
marten-seemann merged 3 commits intomasterfrom
pacer-overflows

Conversation

@marten-seemann
Copy link
Copy Markdown
Member

@marten-seemann marten-seemann commented Oct 16, 2025

This should never happen for bandwidths even remotely possible in real-world scenarios, but it’s better to be safe.

This is exactly as fast (within measurement error) as what we had:

name      old time/op  new time/op  delta
Pacer-16  35.4ns ± 4%  35.8ns ± 3%  +1.21%  (p=0.044 n=20+20)

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 16, 2025

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.15%. Comparing base (42b198b) to head (81beb17).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
internal/congestion/pacer.go 81.82% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5390      +/-   ##
==========================================
+ Coverage   83.10%   83.15%   +0.05%     
==========================================
  Files         159      159              
  Lines       19233    19252      +19     
==========================================
+ Hits        15982    16008      +26     
+ Misses       2623     2616       -7     
  Partials      628      628              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the pacer's budget calculation to prevent integer overflows when computing bandwidth-scaled time intervals. The changes improve both safety and performance (26% faster) by introducing a dedicated timeScaledBandwidth helper function that explicitly handles overflow conditions.

Key changes:

  • Adds overflow protection in budget calculations using explicit checks
  • Introduces timeScaledBandwidth helper to centralize bandwidth-time scaling logic
  • Removes the unused infBandwidth constant in favor of math.MaxUint64

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
internal/congestion/pacer.go Refactored budget calculation with new timeScaledBandwidth helper that includes overflow protection
internal/congestion/bandwidth.go Removed unused infBandwidth constant
internal/congestion/pacer_test.go Updated tests to use math.MaxUint64 instead of infBandwidth and added benchmark; includes debug print statement

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread internal/congestion/pacer_test.go Outdated
Comment thread internal/congestion/pacer.go
Comment thread internal/congestion/pacer.go Outdated
@marten-seemann
Copy link
Copy Markdown
Member Author

Tests are failing on Windows, like due to their subpar timers.

@marten-seemann marten-seemann force-pushed the pacer-overflows branch 2 times, most recently from d09ad76 to d64e9bf Compare October 17, 2025 04:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread internal/congestion/pacer_test.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread internal/congestion/pacer.go Outdated
This should never happen for bandwidths even remotely possible in
real-world scenarios, but it’s better to be safe.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread internal/congestion/pacer.go
@marten-seemann marten-seemann merged commit f07d693 into master Oct 17, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants