Skip to content

feat: Request retry for 429 and 503 responses with exponential backoff#28

Open
andrespd99 wants to merge 2 commits into
mehanizm:masterfrom
andrespd99:master
Open

feat: Request retry for 429 and 503 responses with exponential backoff#28
andrespd99 wants to merge 2 commits into
mehanizm:masterfrom
andrespd99:master

Conversation

@andrespd99

Copy link
Copy Markdown
Contributor

Description

This PR adds automatic request retry with backoff for retryable responses (429 and 503) and customizable parameters.

Changes

Rewrote Client.do to:

  • Ensure request bodies are replayable (set GetBody when missing).
  • Retry up to Client.maxRetries times on HTTP 429 and 503 with exponential backoff and jitter.
  • Drain and close response bodies for intermediate 429/503 responses so connections can be reused.
  • Leave the final 429/503 response body intact so makeHTTPClientError can read it.

Notes and rationale

  • I preserved behavior for non-retryable non-2xx responses by returning makeHTTPClientError immediately.
  • For requests with bodies, I set req.GetBody so each attempt can get a fresh Body reader. This matches how http expects retryable requests to behave.
  • Kept default backoff values conservative (base 100ms, 3 retries). These can be tuned or made configurable if user wants.
  • I avoided closing the response in the final failed attempt so makeHTTPClientError can read the body (it calls io.ReadAll).

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 45.31250% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.22%. Comparing base (b19a753) to head (8228548).

Files with missing lines Patch % Lines
client.go 46.77% 26 Missing and 7 partials ⚠️
errors.go 0.00% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #28      +/-   ##
==========================================
- Coverage   79.59%   76.22%   -3.38%     
==========================================
  Files           9        9              
  Lines         446      408      -38     
==========================================
- Hits          355      311      -44     
- Misses         68       70       +2     
- Partials       23       27       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants