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 55dd0b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 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
1 change: 0 additions & 1 deletion src/cve/utils/vulnerable_dependency_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

from ..data_models.cve_intel import CveIntelNvd
from ..data_models.dependencies import DependencyPackage
from .async_http_utils import request_with_retry
from .clients.intel_client import IntelClient
from .string_utils import package_names_match
from .url_utils import url_join
Expand Down

0 comments on commit 55dd0b1

Please sign in to comment.