From 7083fe6faa386b6bd8583007dbb79bdad8291130 Mon Sep 17 00:00:00 2001 From: Ruben Romero Montes Date: Fri, 13 Dec 2024 12:18:57 +0100 Subject: [PATCH] feat: do not retry for client exceptions Signed-off-by: Ruben Romero Montes --- src/cve/utils/async_http_utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cve/utils/async_http_utils.py b/src/cve/utils/async_http_utils.py index 93fc349..89dba20 100644 --- a/src/cve/utils/async_http_utils.py +++ b/src/cve/utils/async_http_utils.py @@ -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: @@ -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,