Skip to content

Commit 19fc0bc

Browse files
committed
Add logic for handling timeouts to StandardRetryStrategy
1 parent 2f96b6b commit 19fc0bc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/smithy-core/src/smithy_core/retries.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ def acquire(self, *, error: Exception) -> int:
268268
If there's insufficient capacity available, raise an exception.
269269
Otherwise, return the amount of capacity successfully allocated.
270270
"""
271-
capacity_amount = self.RETRY_COST
271+
272+
is_timeout = getattr(error, "is_timeout_error", False)
273+
capacity_amount = self.TIMEOUT_RETRY_COST if is_timeout else self.RETRY_COST
272274

273275
with self._lock:
274276
if capacity_amount > self._available_capacity:

packages/smithy-core/tests/unit/test_retries.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
import pytest
5+
6+
from smithy_core import SmithyError
57
from smithy_core.exceptions import CallError, RetryError
68
from smithy_core.retries import ExponentialBackoffJitterType as EBJT
79
from smithy_core.retries import (
@@ -208,3 +210,13 @@ def test_retry_quota_release_caps_at_max(
208210
# Release more than we acquired. Should cap at initial capacity.
209211
retry_quota.release(release_amount=50)
210212
assert retry_quota.available_capacity == 10
213+
214+
215+
def test_retry_quota_acquire_timeout_error(
216+
retry_quota: StandardRetryQuota,
217+
) -> None:
218+
219+
timeout_error = CallError(is_timeout_error=True, is_retry_safe=True)
220+
acquired = retry_quota.acquire(error=timeout_error)
221+
assert acquired == StandardRetryQuota.TIMEOUT_RETRY_COST
222+
assert retry_quota.available_capacity == 0

0 commit comments

Comments
 (0)