Skip to content

Retries on rate limits#16

Merged
ViacheslavKlimov merged 6 commits intomasterfrom
feature/rate-limits-retries
Mar 12, 2026
Merged

Retries on rate limits#16
ViacheslavKlimov merged 6 commits intomasterfrom
feature/rate-limits-retries

Conversation

@ViacheslavKlimov
Copy link
Copy Markdown
Member

No description provided.

…try-After support

- Wraps a delegate HttpClient and retries 429 responses up to maxRetries times
- Honours Retry-After header (integer seconds) when present
- Falls back to exponential backoff with ±20% jitter
- Both send() and sendAsync() implement retry logic
- isRetriable() is protected for subclass extensibility
- Add retryEnabled, maxRetries, initialRetryDelayMs, maxRetryDelayMs fields to Builder
- installRetryingClient() replaces both auth.httpClient and auth.apiClient.builder
- Auth refresh/re-login calls (AuthManager.httpClient) now benefit from retry
- ThingsboardApi HTTP calls get a RetryingHttpClient via the replaced ApiClient builder
- Make AuthManager.httpClient non-final and package-private to allow replacement
- Update class Javadoc with retry examples and new Builder methods
… common sources to CE

- 5 unit tests covering: no-retry on 200, retry then success, retry exhaustion,
  Retry-After header respect, and isRetriable correctness
- Copy updated RetryingHttpClient and ThingsboardClient from common/ into ce/
  (mirrors what generate-client.sh does; common/ is the source of truth)
- Fix long overflow in exponential backoff by clamping shift to 30
- Rename retryEnabled -> retryOnRateLimit for clarity
- Replace anonymous HttpClient.Builder hack with RetryableApiClient
  subclass that overrides getHttpClient(), eliminating 60 lines
- Restore AuthManager.httpClient to private final
- Unify Builder.build() into a single linear flow
Copy link
Copy Markdown
Member Author

@ViacheslavKlimov ViacheslavKlimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review summary

Reviewed 10 changed files in Retries on rate limits. Clean implementation of RetryingHttpClient with exponential backoff, jitter, and Retry-After support, nicely wired in via RetryableApiClient. Found 0 high-confidence issues and 3 low-confidence observations commented inline.


This review was auto-generated by Claude. Findings may contain errors — please verify before applying changes.

Comment thread common/src/main/java/org/thingsboard/client/RetryingHttpClient.java Outdated
Comment thread common/src/main/java/org/thingsboard/client/RetryingHttpClient.java
Comment thread common/src/main/java/org/thingsboard/client/RetryingHttpClient.java
- Close response body before retrying to avoid leaking connections
- Clamp jittered delay to maxDelayMs so it remains a hard ceiling
- Add comment explaining push-promise sendAsync skips retry
- Move RetryingHttpClientTest from ce/ to common/ where the source lives
@ViacheslavKlimov ViacheslavKlimov merged commit 74fb34a into master Mar 12, 2026
2 checks passed
@ViacheslavKlimov ViacheslavKlimov deleted the feature/rate-limits-retries branch March 12, 2026 13:47
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