GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: implement built-in retry mechanism with exponential backoff and jitter by Deadpool2000 · Pull Request #21 · openapi/openapi-python-sdk

Conversation

@Deadpool2000

@Deadpool2000 Deadpool2000 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Ref issue #20

This PR resolves the lack of a built-in retry mechanism in the SDK client and OAuth client interfaces. Previously, any temporary network dropout, gateway timeout (502/503/504), or rate limit hit (429) would cause immediate request failures and require custom retry handling in the consumer's application.

This change introduces a robust, configurable retry mechanism using exponential backoff and randomized jitter to retry failed requests automatically.


The Problem

  • Low-level HTTP primitives (via httpx) had no automatic retry loop.
  • Transient exceptions (like connection dropouts or request timeouts) crashed consumer applications instantly.
  • Rate-limiting (HTTP 429) was not handled automatically, ignoring Retry-After headers.

The Solution

I implemented an optional, fully backward-compatible retry mechanism across all client classes:

  1. Added Retry Parameters to:
    • Client
    • AsyncClient
    • OauthClient
    • AsyncOauthClient
    • Parameters: max_retries (defaults to 0 for backward compatibility), backoff_factor, and retry_on_status.
  2. Created Retry Loops:
    • _request_with_retry method (both sync and async versions) executes the network calls.
    • Retries trigger on connection/timeout errors (httpx.RequestError) and configured status codes (defaults to [429, 502, 503, 504]).
    • If an HTTP 429 response contains a Retry-After header, the wait time is dynamically overridden to respect the header.
  3. Randomized Jitter: Added random noise to backoff calculations to avoid thundering herd issues on the Openapi gateway.

Key File Changes

  • openapi_python_sdk/client.py: Updates to synchronous Client with sync retry loop.
  • openapi_python_sdk/async_client.py: Updates to asynchronous AsyncClient using asyncio.sleep retry loop.
  • openapi_python_sdk/oauth_client.py: Updates to sync OauthClient wrapping credentials and token operations.
  • openapi_python_sdk/async_oauth_client.py: Updates to async AsyncOauthClient wrapping credentials and token operations.
  • tests/test_retry.py (New): Full unit test coverage for sync retries (testing backoff delays, rate-limit headers, and failures).
  • tests/test_async_retry.py (New): Full unit test coverage for async retries.

How I tested it

  1. Unit Tests:
    • Ran poetry run pytest and verified all 35 tests passed successfully (including existing mocks).
  2. Linter Check:
    • Ran poetry run ruff check . to verify code format styling.
  3. Integration Verification:
    • Tested live connections against httpbin.org testing endpoints to verify that the client retries over multiple attempts and waits exponentially.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Deadpool2000 added 5 commits June 7, 2026 22:46
@Deadpool2000
feat(client): add retry mechanism to synchronous Client
11618d4
@Deadpool2000
feat(async-client): add retry mechanism to AsyncClient
44b08a1
@Deadpool2000
feat(oauth-client): add retry mechanism to OauthClient
69eecb5
@Deadpool2000
feat(async-oauth-client): add retry mechanism to AsyncOauthClient
5815d12
@Deadpool2000
test(retry): add sync and async retry unit test suites
4d01147
@Deadpool2000 Deadpool2000 mentioned this pull request Jun 7, 2026
Lack of built-in retry mechanism for handling transient network errors and rate limits #20
Open
@francescobianco
francescobianco merged commit 7fbc124 into openapi:main Sep 24, 2026
4 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@francescobianco

francescobianco commented Sep 24, 2026

Copy link
Copy Markdown
Member

Thank you for this contribution! 🙌

This is a very useful improvement to the SDK, and I really appreciate the care you put into making it backward-compatible and covering both sync and async clients with tests.

Thanks for taking the time to work on this and contribute to the project!

@Deadpool2000

Deadpool2000 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Deadpool2000 @francescobianco
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.