fix(spammer): reject rates above limiter resolution - #350
Open
Kewe63 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #349
Reject spammer rates above the highest distinct per-second rate supported by the
governorlimiter, and replace the limiter's integer-conversion panics with normal propagated errors.The fix enforces the same upper bound at the CLI, configuration, and rate-limiter layers. It also covers both normal and resumed spammer construction paths.
Problem
The spammer previously exposed
--rateas an unbounded positiveu64:Config::validate()did not enforce an upper bound. The value eventually reachedRateLimiter::new(), which narrowed it with:A rate greater than
u32::MAXtherefore passed CLI and configuration validation, then panicked with:Implementation review also found that
u32::MAXis not the true semantic limit.governor0.8.1 computes its per-token interval as:Rates above
1_000_000_000round this interval down to zero nanoseconds, after which the GCRA implementation clamps it to one nanosecond. Such values fit inu32, but cannot be represented as distinct requested rates.The correct maximum for this path is therefore
1_000_000_000TPS.Changes
MAX_TPSvalue of1_000_000_000at the rate-limiter boundary.--rateparser to1..=MAX_TPS.Config::validate()enforce the same maximum for non-CLI callers.RateLimiter::new()to returnResult<Self>instead of panicking on invalid rate or burst values.Spammer::new()construction;Spammer::new_resuming()construction.Regression Coverage
The new tests verify that:
1_000_000_000is accepted by the CLI;1_000_000_001is rejected by the CLI;Config::validate()accepts the supported maximum;Config::validate()rejects the first unsupported value;RateLimiter::new()accepts the supported maximum;RateLimiter::new()returns an error for the first unsupported value instead of panicking.The rate limiter is fallible independently of CLI/config validation, preventing unvalidated library callers from reaching the old panic path.
RED Verification
Before the fix, focused tests against current
maindemonstrated all three layers of the bug:The CLI, configuration, and limiter regression tests all failed on the previous implementation.
A separate boundary probe confirmed that
u32::MAXdid not panic during construction; review ofgovernor's interval calculation then identified1_000_000_000as the actual distinct-rate limit.How to Test
Focused rejection tests:
cargo +1.94.0 test -p spammer supported_max -- --nocaptureResult:
Supported-boundary tests:
cargo +1.94.0 test -p spammer max_supported_rate -- --nocaptureResult:
Complete package:
cargo +1.94.0 test -p spammerResults:
Additional checks:
All checks passed.
The built CLI was also invoked with both
1_000_000_001and4_294_967_296. Both values now produce a normal Clap validation error with exit code 2. Neither invocation emits panic text or reaches network initialization.Local verification used Rust 1.94.0 because the local pinned 1.93.0 installation has a
cargo-clippycomponent conflict. CI should provide the authoritative pinned-toolchain result.Scope and Risk
The change is limited to spammer rate validation and construction:
It does not change:
1_000_000_000;Rates above
1_000_000_000were previously accepted, butgovernorcould not represent them as distinct rates because of nanosecond resolution. They are now rejected explicitly instead of being rounded or eventually panicking.Duplicate Check
Open and closed issues and pull requests were searched using the issue number, panic text, rate-limiter symbols, type boundary, and supported-rate wording. No duplicate PR or existing implementation was found.
Checklist
maingovernor0.8.1 sourceImpact
Type: 🐛 Bug fix
Fixes: #349