Skip to content

Fix zero-delay reruns with large backoff factors - #389

Open
AryanRG wants to merge 1 commit into
pytest-dev:masterfrom
AryanRG:fix/zero-delay-backoff-388
Open

AryanRG wants to merge 1 commit into
pytest-dev:masterfrom
AryanRG:fix/zero-delay-backoff-388

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 17, 2026

Copy link
Copy Markdown

Fixes #388.

With zero rerun delay and a large positive finite backoff factor, exponentiation can raise before multiplication by zero, aborting pytest before the configured retries complete. Skip exponentiation when the effective delay is zero and keep one time.sleep(0) call per retry. The nonzero-delay formula is unchanged.

Reproduction on unmodified master 01fd226bd533ecd7f6aabe7c155c4ca7bcd8598c (macOS arm64, CPython 3.14.8 / pytest 9.1.1):

# test_zero_backoff.py
def test_eventual_success(request):
    print(f"attempt {request.node.execution_count}")
    assert request.node.execution_count == 4
python -m pytest -q -s -p no:randomly -p no:cacheprovider \
  --reruns 3 --reruns-delay 0 --reruns-delay-backoff-factor 1e308 \
  test_zero_backoff.py

Before: three attempts, 2 rerun, INTERNALERROR> OverflowError: (34, 'Result too large'), exit 3. After: four attempts, 1 passed, 3 rerun, exit 0. Both reproductions used real sleep calls. 1e308 is finite; this is an edge case involving an unusually large factor. Nonzero-delay overflow remains outside this fix.

Add a regression that checks fourth-attempt recovery and three zero sleeps, plus the issue-numbered changelog fragment.

Validation on macOS arm64, CPython 3.14.8 / pytest 9.1.1, with pytest-xdist 3.8.0 installed:

  • Focused backoff tests: 5 passed, 254 deselected.
  • Full local suite: 259 passed.
  • Real-sleep reproduction with two xdist workers: 1 passed, 3 rerun, exit 0.
  • All nine pinned pre-commit hooks passed on an isolated complete copy; hooks made no changes.
  • git diff --check, Towncrier draft rendering, and towncrier check --compare-with 01fd226bd533ecd7f6aabe7c155c4ca7bcd8598c on the committed branch passed; the fragment links to Zero rerun delay can abort with OverflowError for a large finite backoff factor #388.
  • Independent AI review approved these exact source/test bytes and the corrected fragment. That review previously ran 259 full-suite tests and 55 additional probes; the 55 probes were not rerun during publication.

AI assistants were used for the investigation, reproduction, tests, review, and drafting with the account owner's authorization. The independent review was by an AI assistant; human maintainer review is pending. The full supported Python/pytest matrix, Linux/Windows, PyPy, free-threaded Python, and docs/package builds were not run locally for this patch. Hosted CI results will be reported by GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zero rerun delay can abort with OverflowError for a large finite backoff factor

1 participant