Retry HTTP 503 responses#359
Open
winklemad wants to merge 1 commit into
Open
Conversation
`retry_if_specific_error` listed the retryable status codes as
`{429, 500, 502, 504, 500}` -- 500 appears twice and 503 is missing, so a
transient HTTP 503 Service Unavailable is never retried even though its sibling
upstream errors 502 and 504 are. 503 is the canonical "try again later" status
(load balancer draining, deploy, overload), so a request that hits one is
returned to the caller as an error on the first attempt.
Replace the duplicate 500 with 503, making the set `{429, 500, 502, 503, 504}`.
Added a test asserting the transient statuses are retried and that non-transient
or non-`ESMProteinError` errors are not.
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.
No linked issue — found by reading the code.
The bug
retry_if_specific_error(esm/sdk/retry.py) lists the retryable HTTP status codes as:500appears twice and503is absent, so the set is effectively{429, 500, 502, 504}. A transient HTTP 503 Service Unavailable is therefore never retried — even though its sibling upstream errors 502 Bad Gateway and 504 Gateway Timeout are.503is the canonical "try again later" status (load-balancer draining, deploy rollover, server overload, and it often carriesRetry-After), so a request that hits one is returned to the caller as anESMProteinErroron the very first attempt instead of being retried with backoff.base_forge_clientsetserror_codefrom the response status, so a real 503 arrives here as exactly503:The duplicate
500is the smoking gun — a status code isn't listed twice on purpose; one of those slots was meant to be503.Fix
Replace the duplicate
500with503, making the set{429, 500, 502, 503, 504}.Testing
Added
esm/sdk/retry_test.pyasserting that the transient statuses429/500/502/503/504are retried, and that a non-transient client error (404) and a non-ESMProteinErrorexception are not. The 503 case fails before this change and passes after;ruff check/ruff formatare clean.