Skip to content

Add configurable maxBackoffMs for rate limit retries#103

Open
jeffreyparker wants to merge 9 commits intomasterfrom
feature/configurable-max-backoff
Open

Add configurable maxBackoffMs for rate limit retries#103
jeffreyparker wants to merge 9 commits intomasterfrom
feature/configurable-max-backoff

Conversation

@jeffreyparker
Copy link

@jeffreyparker jeffreyparker commented Feb 23, 2026

Summary

  • Adds a useMaxBackoffMs() method to the ClientBuilder so callers can configure the maximum backoff threshold for 429 (rate limit) retry logic.
  • Setting maxBackoffMs to 0 disables retries entirely.
  • Default behavior (32000ms max backoff) is preserved.

Note: The response.close(); line fixes a preexisting issue where retries hold the connection open instead of closing them, potentially exhausting the pool.

Test plan

  • Unit test: testMaxBackoffZeroDisablesRetry — verifies that setting maxBackoff to 0 returns the 429 immediately with no retries.
  • Unit test: testMaxBackoffCustomLimit — verifies that a custom limit (4000ms) caps retries correctly.
  • Existing retry tests continue to pass with default behavior.

Allow callers to configure the maximum backoff threshold for 429 retry
logic via a new useMaxBackoffMs() builder method. Setting maxBackoffMs
to 0 disables retries entirely. The default (32000ms) preserves existing
behavior.
- Reject negative values in both useMaxBackoffMs() builder method and
  setMaxBackoffMs() setter with IllegalArgumentException
- Clarify Javadoc that maxBackoffMs is the base backoff threshold before
  jitter (actual sleep includes up to 1000ms random jitter)
- Add test for negative value rejection
@jeffreyparker jeffreyparker marked this pull request as ready for review March 10, 2026 19:57
…erver

Tests use a real HTTPS server (OkHttp MockWebServer + okhttp-tls) to verify
end-to-end retry behavior: single retry with success, exhausting the default
32s max backoff, a custom max backoff limit, and zero backoff disabling retries.
…tion

Clarify that values below INITIAL_BACKOFF_MS (1000ms) also effectively
disable retries, and document the ClientBuilder visibility limitation
that prevents fluent method chaining from outside the package.
Rename HttpRateLimitRetryIntegrationTest to *IT (failsafe naming
convention) and add maven-failsafe-plugin so socket-binding tests
run in the integration-test phase instead of the default test phase.
The testRepeatRetryAfterRateLimit test already covers default backoff
behavior (7 requests = 32s max) through observable retry count.
@jeffreyparker jeffreyparker force-pushed the feature/configurable-max-backoff branch from 3f7dd60 to a481565 Compare March 10, 2026 21:31
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