Repository navigation
[extended] Fix int overflow in exponential backoff rate limiter - #4957
Draft
yue9944882 wants to merge 1 commit into
Draft
yue9944882 wants to merge 1 commit into
yue9944882 wants to merge 1 commit into
Conversation
Contributor
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: yue9944882 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
ItemExponentialFailureRateLimiter.when() computed the backoff multiplier as 1 << exp, an int shift. Once exp reaches 31 the shift overflows to Integer.MIN_VALUE (and wraps thereafter), so baseDelay.multipliedBy(...) returns a negative Duration whenever maxDelay is large enough that the baseDelay*2^exp branch is still selected at that failure count. Compute the multiplier in long arithmetic (1L << exp), matching the long type of exp and of Duration.multipliedBy(long). Add a regression test that fails before and passes after.
yue9944882
force-pushed
the
fix/extended-expbackoff-int-overflow
branch
from
October 22, 2026 17:27
2264c25 to
b02272f
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.
Bug
ItemExponentialFailureRateLimiter.when()(extended module, work-queue rate limiters) computes the backoff multiplier as1 << exp:expis along, but1 << expis evaluated in int arithmetic (the shift result type follows the left operand, and the distance is masked to 5 bits). Onceexpreaches 31,1 << 31overflows toInteger.MIN_VALUE(and wraps for higher counts). WhenmaxDelayis large enough that thebaseDelay * 2^expbranch is still selected at that failure count,baseDelay.multipliedBy(...)then returns a negativeDuration— never a valid backoff.Fix
Compute the multiplier in
longarithmetic:1L << exp. This matches thelongtype ofexpand ofDuration.multipliedBy(long), and is behavior-preserving for allexp < 31(where1 << exp == 1L << exp).Verification
Added a focused regression test
highFailureCountStaysPositivethat drives the item toexp == 31with a largemaxDelayand asserts the backoff stays positive and equalsbaseDelay * 2^31.highFailureCountStaysPositiveFAILS (negative duration).ItemExponentialFailureRateLimiterTestPASS.Draft pending maintainer review.