Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy request for each attempt / don't retry client errors #460

Merged
merged 5 commits into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -132,6 +132,7 @@ private void generateOperationExecutor(PythonWriter writer) {
writer.addStdlibImport("typing", "Awaitable");
writer.addStdlibImport("typing", "cast");
writer.addStdlibImport("copy", "deepcopy");
writer.addStdlibImport("copy", "copy");
writer.addStdlibImport("asyncio");
writer.addStdlibImports("asyncio", Set.of("sleep", "Future"));
writer.addStdlibImport("dataclasses", "replace");
@@ -395,7 +396,10 @@ def _classify_error(
output_context = await self._handle_attempt(
deserialize,
interceptor_chain,
request_context,
replace(
request_context,
transport_request = copy(request_context.transport_request)
),
config,
operation,
request_future,
19 changes: 12 additions & 7 deletions packages/smithy-core/src/smithy_core/retries.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
from dataclasses import dataclass
from enum import Enum

from smithy_core.interfaces.retries import RetryErrorType

from .exceptions import SmithyRetryException
from .interfaces import retries as retries_interface

@@ -232,13 +234,16 @@ def refresh_retry_token_for_retry(

:raises SmithyRetryException: If no further retry attempts are allowed.
"""
retry_count = token_to_renew.retry_count + 1
if retry_count >= self.max_attempts:
raise SmithyRetryException(
f"Reached maximum number of allowed attempts: {self.max_attempts}"
)
retry_delay = self.backoff_strategy.compute_next_backoff_delay(retry_count)
return SimpleRetryToken(retry_count=retry_count, retry_delay=retry_delay)
if error_info.error_type is not RetryErrorType.CLIENT_ERROR:
retry_count = token_to_renew.retry_count + 1
if retry_count >= self.max_attempts:
raise SmithyRetryException(
f"Reached maximum number of allowed attempts: {self.max_attempts}"
)
retry_delay = self.backoff_strategy.compute_next_backoff_delay(retry_count)
return SimpleRetryToken(retry_count=retry_count, retry_delay=retry_delay)
else:
raise SmithyRetryException(f"Error is not retryable: {error_info}")

def record_success(self, *, token: retries_interface.RetryToken) -> None:
"""Not used by this retry strategy."""
13 changes: 13 additions & 0 deletions packages/smithy-core/tests/unit/test_retries.py
Original file line number Diff line number Diff line change
@@ -72,3 +72,16 @@ def test_simple_retry_strategy(max_attempts: int) -> None:
strategy.refresh_retry_token_for_retry(
token_to_renew=token, error_info=error_info
)


def test_simple_retry_strategy_does_not_retry_client_errors() -> None:
strategy = SimpleRetryStrategy(
backoff_strategy=ExponentialRetryBackoffStrategy(backoff_scale_value=5),
max_attempts=2,
)
error_info = RetryErrorInfo(error_type=RetryErrorType.CLIENT_ERROR)
token = strategy.acquire_initial_retry_token()
with pytest.raises(SmithyRetryException):
strategy.refresh_retry_token_for_retry(
token_to_renew=token, error_info=error_info
)