Repository navigation
Implement Adaptive retries - #842
Merged
Merged
Conversation
* Implement a token bucket used for adaptive retries
* Implement client-side rate limiting for adaptive retries.
* Implement Adaptive retry strategy for Adaptive retries.
Alan4506
reviewed
Oct 14, 2026
alexgromero
reviewed
Oct 14, 2026
alexgromero
reviewed
Oct 14, 2026
Alan4506
previously approved these changes
Oct 15, 2026
alexgromero
reviewed
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue #, if available:
Description of changes:
Adds the adaptive retry mode. It builds on standard retries by adding client-side rate limiting: once the service starts throttling, the client slows its send rate. The work was reviewed in three PRs and merged into the
adaptive_retriesfeature branch:Behavior:
RetryStrategyResolvernow caches strategies per client instead of in a shared 128-entry cache with@lru_cache, so a client's rate limiter state isn't reset when many other clients are created.AWS_RETRY_MODE=adaptive(orretry_mode = adaptivein a config profile) now selects adaptive mode instead of falling back to standard with a warning.smithy_core.aio.retriesThread safety: threading.Lock instead of asyncio.Lock
An
asyncio.Lockonly coordinates tasks on a single event loop. If one client is used from several threads, each running its own loop, the token count, measured send rate and CUBIC state could have a race condition, and calls could fail. The short sections that update this state now use athreading.Lock, which is whatStandardRetryQuotaalready does.A thread lock is fine here because it only covers a few lines of arithmetic. It's never held across an await, and never while waiting for a token, so it doesn't block for any meaningful time. This follows earlier discussions:
threading.Lockworks in place ofasyncio.Lock(comment (Add standard retry mode #545 (comment)))Why the
asyncio.Conditionstays: waiting for a token is real waiting. A request pauses until tokens refill or the rate changes, and other requests keep running in the meantime. The bucket keeps one Condition per event loop, used only for waiting and wakeups. The thread lock is released before waiting.Testing:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.