Skip to content

Commit 68dd5f0

Browse files
lesnik512claude
andcommitted
fix(resilience): backoff uses 2.0 ** to avoid OverflowError on large attempt_index
base_delay * (2 ** attempt_index) raises OverflowError at attempt_index >= 1024 because 2**1024 is too large for int→float conversion. Float exponentiation saturates to math.inf, which min() then clamps to max_delay. The current Retry default max_attempts=3 makes this unreachable in practice, but the function takes attempt_index unbounded, so closing the trap is a one-char fix at zero behavior cost. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6325345 commit 68dd5f0

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎src/httpware/middleware/resilience/_backoff.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ def full_jitter_delay(
1313
) -> float:
1414
"""Return a backoff delay using AWS's "full jitter" formulation.
1515
16-
sleep = uniform(0, min(max_delay, base_delay * 2 ** attempt_index))
16+
sleep = uniform(0, min(max_delay, base_delay * 2.0 ** attempt_index))
1717
1818
`attempt_index` is 0 for the first retry, 1 for the second, etc.
19+
20+
Uses ``2.0 **`` (float exponentiation) rather than ``2 **`` so that
21+
``attempt_index >= 1024`` saturates to ``math.inf`` and ``min`` clamps to
22+
``max_delay`` — ``2 ** 1024`` would raise ``OverflowError`` during the
23+
int→float conversion.
1924
"""
20-
ceiling = min(max_delay, base_delay * (2**attempt_index))
25+
ceiling = min(max_delay, base_delay * (2.0**attempt_index))
2126
return _random_uniform(0.0, ceiling)

0 commit comments

Comments
 (0)