jd / jd/tenacity

Zero exponential multiplier can overflow into maximum wait

Open
#710 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
8.8k
Forks
359
Avg merge
1m
Merged PRs (30d)
1

Description

Setting an exponential multiplier to zero can unexpectedly produce the maximum wait after enough attempts. I reproduced this on main (`3e58094d3`) with Python 3.13.13:

```python
from types import SimpleNamespace
from tenacity import wait_exponential, wait_exponential_jitter

state = SimpleNamespace(attempt_number=1025)
print(wait_exponential(multiplier=0.0, max=60)(state))
print(wait_exponential(multiplier=0, exp_base=2.0, max=60)(state))
print(wait_exponential_jitter(multiplier=0.0, jitter=0, max=60)(state))
```

All three calls return `60.0`; the expected wait is zero. With a configured minimum, the zero exponential contribution should leave that minimum in effect. The jitter strategy should also retain its random contribution.

The power is calculated before multiplication by zero. A floating-point power can overflow; multiplying the large integer power by `0.0` also overflows while converting that integer to a float. Both paths fall into the overflow handler and use the maximum. `wait_random_exponential` inherits the same upper-bound problem.

This makes a configured zero backoff begin waiting at the cap after many retries. A bounded regression at attempt 1025 reproduces the behavior without sleeping or performing any retries.

OpenAI Codex assisted with investigation, reproduction, and this report.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the wait_exponential, wait_exponential_jitter, and wait_random_exponential entry points, then run the bounded attempt-1025 reproduction from the report. Check the zero-multiplier, minimum, jitter, and upper-bound behavior without sleeping or retrying; done means zero remains zero, configured minimums remain effective, jitter is retained, and random exponential waits do not incorrectly reach the cap.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.