Skip to content

Dual-path retry: exponential backoff + rate-limit handling#206

Open
MichaelGHSeg wants to merge 2 commits into
v3.0from
status-response-update
Open

Dual-path retry: exponential backoff + rate-limit handling#206
MichaelGHSeg wants to merge 2 commits into
v3.0from
status-response-update

Conversation

@MichaelGHSeg
Copy link
Copy Markdown
Contributor

Summary

Replaces the fixed 10-attempt retry loop with a structured dual-path retry system that separates rate-limiting (429 + Retry-After) from general transient failures.

  • 429 + Retry-After header: sleep for the specified duration (capped at 300s), does NOT consume the retry budget. Bounded by MaxRateLimitDuration (default 12h).
  • Other retryable errors (5xx, 408, 410, 460): counted exponential backoff (base 500ms, 2×, cap 60s). Bounded by MaxRetries (default 10) and MaxTotalBackoffDuration (default 12h).
  • Non-retryable errors (4xx except the above, plus 501/505/511): discard immediately.
  • Removes select { case <-c.quit } from retry sleep paths — Close() now waits for in-flight retries to finish naturally via wg.Wait() instead of killing them mid-flight.
  • Adds X-Retry-Count header on retry attempts (omitted on first attempt).
  • Wraps body-read errors in httpError preserving the original status code's retryability (fixes a bug where a non-retryable 4xx with a broken response body would be incorrectly retried).
  • New config fields: MaxRetries, MaxTotalBackoffDuration, MaxRateLimitDuration.
  • New sentinel errors: ErrBackoffBudgetExceeded, ErrRateLimitBudgetExceeded.
  • E2E: enables retry test suite; wires maxRetries from e2e-cli input config.

Test plan

  • go test -race ./... passes
  • E2E basic,retry suites pass (48/48)

…dling

Replace the fixed 10-attempt retry loop with a structured retry system:
- 429 + Retry-After: sleep without consuming retry budget, capped by
  MaxRateLimitDuration
- Other retryable errors: counted exponential backoff (base 500ms, 2x,
  cap 60s) bounded by MaxRetries and MaxTotalBackoffDuration
- Non-retryable status codes (4xx except 408/410/429/460, plus
  501/505/511) discard immediately
- Remove select on c.quit from retry sleeps so Close() waits for
  in-flight retries to complete naturally via wg.Wait()
- Add X-Retry-Count header on retry attempts
- Wire MaxRetries config through to e2e-cli
- Enable retry test suite in e2e-config
When io.ReadAll fails on a non-2xx response, wrap the error in httpError
with the original status code's retryability instead of returning a raw
error (which would be treated as a network error and always retried).
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.

1 participant