-
Notifications
You must be signed in to change notification settings - Fork 1
🛡️ Sentinel: Fix unbounded retries on client errors #191
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -600,6 +600,17 @@ | |||||||||||||||||||||||||||||||||
| response.raise_for_status() | ||||||||||||||||||||||||||||||||||
| return response | ||||||||||||||||||||||||||||||||||
| except (httpx.HTTPError, httpx.TimeoutException) as e: | ||||||||||||||||||||||||||||||||||
| # Security Enhancement: Do not retry client errors (4xx) except 429 (Too Many Requests). | ||||||||||||||||||||||||||||||||||
| # Retrying 4xx errors is inefficient and can trigger security alerts or rate limits. | ||||||||||||||||||||||||||||||||||
| if isinstance(e, httpx.HTTPStatusError): | ||||||||||||||||||||||||||||||||||
| code = e.response.status_code | ||||||||||||||||||||||||||||||||||
| if 400 <= code < 500 and code != 429: | ||||||||||||||||||||||||||||||||||
| if hasattr(e, "response") and e.response is not None: | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+603
to
+608
|
||||||||||||||||||||||||||||||||||
| log.debug( | ||||||||||||||||||||||||||||||||||
| f"Response content: {sanitize_for_log(e.response.text)}" | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+606
to
+611
|
||||||||||||||||||||||||||||||||||
| code = e.response.status_code | |
| if 400 <= code < 500 and code != 429: | |
| if hasattr(e, "response") and e.response is not None: | |
| log.debug( | |
| f"Response content: {sanitize_for_log(e.response.text)}" | |
| ) | |
| # Ensure the response exists before accessing status_code or text. | |
| # While httpx.HTTPStatusError is expected to always have a response, | |
| # this guard keeps the code robust against library or usage changes. | |
| if not hasattr(e, "response") or e.response is None: | |
| raise | |
| code = e.response.status_code | |
| if 400 <= code < 500 and code != 429: | |
| log.debug( | |
| f"Response content: {sanitize_for_log(e.response.text)}" | |
| ) |
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Use lazy % formatting in logging functions Note
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The heading/description calls this "Unbounded Retries", but
_retry_requestis bounded byMAX_RETRIES(currently 10). To avoid misleading future readers, consider rewording to "Retries on client errors (4xx)" (or similar) and keep the DoS discussion focused on unnecessary repeated requests rather than "unbounded" behavior.