Skip to content

Commit

Permalink
feat: do not retry for client exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
  • Loading branch information
ruromero committed Dec 13, 2024
1 parent f85251e commit 7083fe6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/cve/utils/async_http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ async def request_with_retry(session: aiohttp.ClientSession,
max_retries: int = 10,
sleep_time: float = 0.1,
respect_retry_after_header: bool = True,
log_on_error=True) -> typing.AsyncIterator[aiohttp.ClientResponse]:
log_on_error=True,
retry_on_client_errors = False) -> typing.AsyncIterator[aiohttp.ClientResponse]:
"""
Async version of `morpheus.utils.http_utils.request_with_retry`
"""
assert not request_kwargs.get('raise_for_status'), "raise_for_status is cincompatible with `request_with_retry`"
assert not request_kwargs.get('raise_for_status'), "raise_for_status is incompatible with `request_with_retry`"
try_count = 0
done = False
while try_count <= max_retries and not done:
Expand All @@ -61,6 +62,8 @@ async def request_with_retry(session: aiohttp.ClientSession,
actual_sleep_time = max(int(response_headers["Retry-After"]), actual_sleep_time)
elif respect_retry_after_header and 'X-RateLimit-Reset' in response_headers:
actual_sleep_time = max(int(response_headers["X-RateLimit-Reset"]) - time.time(), actual_sleep_time)
elif not retry_on_client_errors and response.status < 500:
raise e

logger.warning("Error requesting [%d/%d]: (Retry %.1f sec) %s: %s",
try_count,
Expand Down

0 comments on commit 7083fe6

Please sign in to comment.