Skip to content

Refactor RetryStrategy to be async#671

Open
JordonPhillips wants to merge 1 commit intodevelopfrom
async-retry-2
Open

Refactor RetryStrategy to be async#671
JordonPhillips wants to merge 1 commit intodevelopfrom
async-retry-2

Conversation

@JordonPhillips
Copy link
Copy Markdown
Contributor

This refactors RetryStrategy to be async. This is necessary because a strategy may need to use a synchronization primitive or may need to internally wait.

For example, AWS retry strategies may need to wait internally even if a retry would not be permitted if the operation is a long-poll operation.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

This refactors retry strategies to be async. This is needed for
when strategies need to internally wait or if they need to
protect access to a shared resource.
@JordonPhillips JordonPhillips requested a review from a team as a code owner March 27, 2026 16:10
Copy link
Copy Markdown
Contributor

@ubaskota ubaskota left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. It looks good overall. I have some clarifying questions inline where I could add them, plus two more below that didn't fit in any specific part:



  • The PR description mentions long-poll operations as motivation, and notes that a strategy "may need to wait internally." The current implementations only do computation (backoff math, quota checks) and no I/O operations. What does "waiting internally" mean concretely here?

  • Should designs/retries.md file be updated with the change? Adding it here since GitHub doesn't let me comment on unchanged files.


@lru_cache
def _create_retry_strategy(
self, retry_mode: RetryStrategyType, max_attempts: int | None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_create_retry_strategy is synchronous with @lru_cache. Is this intentional? It's just creating and returning retry strategy today, but do you see a case where this would need to be async?

"""
self._max_capacity = initial_capacity
self._available_capacity = initial_capacity
self._lock = threading.Lock()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is leaving threading.Lock intentional? If so, do you think it's worth adding a short comment explaining the choice? And do you see a scenario where we may need to make this async?

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