fix: stop Retry-After HTTP dates without a zone or out of range from crashing the retry - #143
Merged
Merged
Conversation
…crashing the retry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two crashes in
_parse_retry_after, the parser behind honouring aRetry-Afterheader. 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_datetimereturns 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 awarenowraises "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
OverflowErroron 3.11 and 3.12. A huge year or offset overflows insideparsedate_to_datetime; 3.13 converts that toValueError, 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 throughdecide.TypeError, 2×OverflowError. Red on 3.13: 3×TypeError(the out-of-range cases already passed there).just lint-ciclean;just test-ci: 824 passed, 100 % coverage.