Repository navigation
Prevent overflow in capped exponential backoff - #300
Merged
Merged
Conversation
llucax
marked this pull request as ready for review
November 30, 2026 13:52
llucax
enabled auto-merge
November 30, 2026 14:05
llucax
force-pushed
the
fix-backoff-overflow
branch
from
November 30, 2026 14:15
5315f34 to
eff2479
Compare
Contributor
There was a problem hiding this comment.
It seems there is at least one edge case that still fails.
With initial_interval=0.0, the delay should come entirely from jitter but retry 1_025 still raises OverflowError.
Regression tests using the existing retry and MockerFixture imports:
def test_zero_initial_interval_keeps_retrying(mocker: MockerFixture) -> None:
"""Keep using jitter when the initial interval is zero."""
mocker.patch("random.uniform", return_value=0.5)
strategy = retry.ExponentialBackoff(initial_interval=0.0)
for _ in range(1_025):
assert strategy.next_interval() == 0.5
def test_large_multiplier_can_reach_cap() -> None:
"""Reach the cap even if the multiplier's power would overflow."""
strategy = retry.ExponentialBackoff(
initial_interval=1e-200, multiplier=1e200, max_interval=60.0, jitter=0.0
)
assert strategy.next_interval() == 1e-200
assert strategy.next_interval() == 1.0
assert strategy.next_interval() == 60.0
Contributor
Author
|
Good catch. I will also add a commit to validate inputs, because as things are now, it accepts negative intervals for example. |
Negative and nonfinite timing values can produce unusable retry delays. Reject them at construction so callers get a clear error before retrying. Check the range before converting to float so out-of-range integers also raise ValueError. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Skip the power once a growing interval reaches the cap. A zero initial interval needs only jitter. If the power overflows before the cap is reached, calculate the scaled interval in log space before applying jitter and the cap. The power can overflow even if the scaled interval is still below the cap. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
llucax
force-pushed
the
fix-backoff-overflow
branch
from
December 1, 2026 08:46
d7bd997 to
10f9e24
Compare
Contributor
Author
|
Updated. |
daniel-zullo-frequenz
approved these changes
Dec 1, 2026
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.
An unlimited exponential backoff can stop retrying during a long outage. With the default multiplier, the power overflows on retry 1,025 even though the interval has already reached its cap. I skip the power once all subsequent intervals are guaranteed to be capped.
Fixes #299.