Skip to content

Fix: Honor Retry-After on 5xx responses, not just 429 - #616

Closed
ffumero2003 wants to merge 1 commit into
masterfrom
honor-retry-after-on-5xx
Closed

ffumero2003 wants to merge 1 commit into
masterfrom
honor-retry-after-on-5xx

Conversation

@ffumero2003

Copy link
Copy Markdown
Contributor

Problem

A 5xx carrying Retry-After: N is ignored — the client retries on its default backoff
(~1s) instead of waiting N seconds, unlike 429 which honors the header.

Root cause

In b2sdk/_internal/exception.py, the 500 <= status < 600 branch builds ServiceError
from the message only and never reads response_headers, and ServiceError had no
retry_after_seconds slot (only TooManyRequests did). b2http already honors a non-None
retry_after_seconds on read — only the write side was missing.

Fix

  • Give ServiceError __init__(self, *args, retry_after_seconds=None) that stores the value
    (mirrors TooManyRequests).
  • Pass retry_after_seconds=response_headers.get('retry-after') from the 5xx branch.

Verification

  • New unit tests: a ServiceError from a 503 with Retry-After: 200 has
    retry_after_seconds == 200, and None without it. Red before, green after; full unit
    suite green across all apivers.
  • Resolves the api.retry_after_503 resilience failure (FAIL → PASS).

Fixes #606

A 5xx carrying Retry-After was ignored: the client retried on its default
backoff instead of waiting the requested time, unlike 429. Give ServiceError a
retry_after_seconds slot (mirroring TooManyRequests) and pass the header from the
5xx branch of interpret_b2_error; b2http already honors a non-None value.
@ffumero2003
ffumero2003 deleted the honor-retry-after-on-5xx branch September 30, 2026 19:28
@ffumero2003
ffumero2003 restored the honor-retry-after-on-5xx branch September 30, 2026 19:30
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.

Retry-After is honored on 429 but structurally cannot be read on any 5xx response

1 participant