feat: retry transient gateway 5xx via urllib3 Retry (#139)#144
Merged
Conversation
…sion Closes #139 The prod edge intermittently returns 502/503/504 under load (documented in conftest, which retried them only for the test suite). Consumers got a ServerError on the first blip. Mount a urllib3 Retry adapter on the shared Session: retries transient statuses + connect/read failures on GETs, honors Retry-After, backoff. raise_on_status=False so an exhausted retry still flows through _handle_exception as ServerError (error contract unchanged). On by default (max_retries=3); tunable via max_retries/retry_backoff/ retry_statuses, max_retries=0 to disable. Verified end-to-end (503,503,200 -> one transparent success; max_retries=0 -> ServerError on first 503).
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.
Closes #139
Summary
First of the roadmap issues. The prod edge intermittently returns
502/503/504under load —tests/conftest.pyalready documents and retries this, but only for the test suite, so real consumers got aServerErroron the first transient blip.Mount a
urllib3.util.retry.Retryadapter on the sharedSession(the single one introduced in #137):retry_statuses(default502, 503, 504) + connection/read failures, GET only (all endpoints are GET).backoff_factorbetween attempts, honorsRetry-After.raise_on_status=Falseso an exhausted retry returns the final response and the SDK's own_handle_exceptionstill raisesServerError— error contract unchanged, no leaked urllib3MaxRetryError.On by default (
max_retries=3). Tunable viamax_retries/retry_backoff/retry_statuses;max_retries=0disables. Rides through**kwargs, soDatamaxi(api_key, max_retries=...)reaches every sub-client.Design choices (confirmed before implementing)
max_retries=0.Tests / verification
tests/test_retry.py(5 tests): asserts the mounted policy config (total,status_forcelist, backoff,respect_retry_after_header,raise_on_status, GET-only),max_retries=0, tunability, shared adapter, and propagation throughDatamaxi.responsesintercepts above urllib3, so it can't drive retries — verified end-to-end against a local server instead: default client503,503,200→ one transparent success (3 hits);max_retries=0→ServerErroron the first503.pytest -m "not integration": 139 passed, 11 skipped (was 134 + 5 new).Notes
responsesbypasses the adapter Retry, so existing 5xx tests stay fast and still assertServerError.Known failures
None.