Conversation
ggarri
reviewed
Dec 20, 2024
ggarri
reviewed
Dec 20, 2024
ggarri
approved these changes
Dec 20, 2024
1f7a48f to
5de460b
Compare
00ed6ee to
bedabb3
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
…e how out-of-range priorities are handled. Three built-in validators are provided: OnInvalidPriorityClamp (default), OnInvalidPriorityError, and OnInvalidPriorityPanic. The default behaviour changes from a runtime index-out-of-bounds panic to clamping the priority to the lowest valid level with a warning log, which is more appropriate for a library used in production request paths.
bedabb3 to
2b38b56
Compare
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.

This PR allows configuration of how Bulwark handles out-of-range priority values. Three built-in options cover the common use cases:
process.
The previous behaviour was an implicit runtime panic (index out of bounds) whenever an invalid priority was passed to Throttle or WithAdaptiveThrottle. Since priority values can come from configuration or user input, crashing the process is a disproportionate response — hence the safer clamp default.
The custom validator can be set via WithPriorityValidator(fn).
Note
Medium Risk
Changes how invalid priorities are handled across all throttle entrypoints (clamp/log vs error/panic), which can affect runtime behavior and error paths for callers.
Overview
Adaptive throttling now validates request priority values before indexing counters, avoiding the previous out-of-bounds panic behavior.
NewAdaptiveThrottlestores the configured priority count, defaults to a safeClampInvalidPriorityvalidator, and rejectspriorities <= 0.Throttle, genericThrottle[T], andWithAdaptiveThrottle[T]now run the validator and may return an error before invoking the throttled function.Adds
WithPriorityValidatorplus built-in validators (AssertValidPriority,ClampInvalidPrioritywith warning log, andRejectInvalidPriority) with accompanying tests.Written by Cursor Bugbot for commit 2b38b56. This will update automatically on new commits. Configure here.