Skip to content

fix: stop Retry-After HTTP dates without a zone or out of range from crashing the retry - #143

Merged
lesnik512 merged 1 commit into
mainfrom
fix/retry-after-date-crashes
Sep 27, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
fix/retry-after-date-crashes

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Two crashes in _parse_retry_after, the parser behind honouring a Retry-After header. Both escaped _RetryPolicy.decide, so a server's odd header turned a retryable response into an unexpected exception.

1. A date with no usable zone raised TypeError. email.utils.parsedate_to_datetime returns a naive datetime for -0000, a missing zone, or an unknown zone name (checked on 3.11, 3.12 and 3.13), and subtracting it from the aware now raises "can't subtract offset-naive and offset-aware datetimes". RFC 9110 fixes an HTTP-date to GMT, so a naive result is read as UTC.

2. An out-of-range date raised OverflowError on 3.11 and 3.12. A huge year or offset overflows inside parsedate_to_datetime; 3.13 converts that to ValueError, which was already caught, but 3.11 and 3.12 (both in the matrix) let it escape. It is now caught with the other malformed-input errors, so the header is ignored and the normal backoff applies.

Test-first: two parametrized tests in tests/test_retry_policy.py, driven through decide.

  • Red on 3.11: 3× TypeError, 2× OverflowError. Red on 3.13: 3× TypeError (the out-of-range cases already passed there).
  • Green on both; just lint-ci clean; just test-ci: 824 passed, 100 % coverage.

@lesnik512
lesnik512 merged commit 160acbd into main Sep 27, 2026
13 checks passed
@lesnik512
lesnik512 deleted the fix/retry-after-date-crashes branch September 27, 2026 17:14
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.

1 participant