Repository navigation
fix(web, audit_logs, scim, webhook): pass the status error to async retry handlers #2080
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
Open
WilliamBergamin
wants to merge
3
commits into
main
Choose a base branch
from
fix/async-retry-status-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+179
−17
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
0b11359
fix(web, audit_logs, scim, webhook): pass the status error to async r…
WilliamBergamin 9e7fcbd
refactor(http_retry): take the async status error from raise_for_status
WilliamBergamin 788588d
refactor(web, audit_logs, scim, webhook): catch the async status erro…
WilliamBergamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,20 +162,40 @@ def convert_params(values: dict) -> dict: | |
| f"body: {body}" | ||
| ) | ||
|
|
||
| for handler in retry_handlers: | ||
| if await handler.can_retry_async( | ||
| state=retry_state, | ||
| request=retry_request, | ||
| response=retry_response, | ||
| ): | ||
| if logger.level <= logging.DEBUG: | ||
| logger.info(f"A retry handler found: {type(handler).__name__} for {http_verb} {api_url}") | ||
| await handler.prepare_for_next_attempt_async( | ||
| try: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (non-blocking): The two handler loops only differ by |
||
| res.raise_for_status() | ||
| except aiohttp.ClientResponseError as e: | ||
| for handler in retry_handlers: | ||
| if await handler.can_retry_async( | ||
| state=retry_state, | ||
| request=retry_request, | ||
| response=retry_response, | ||
| ) | ||
| break | ||
| error=e, | ||
| ): | ||
| if logger.level <= logging.DEBUG: | ||
| logger.info(f"A retry handler found: {type(handler).__name__} for {http_verb} {api_url}") | ||
| await handler.prepare_for_next_attempt_async( | ||
| state=retry_state, | ||
| request=retry_request, | ||
| response=retry_response, | ||
| error=e, | ||
| ) | ||
| break | ||
| else: | ||
| for handler in retry_handlers: | ||
| if await handler.can_retry_async( | ||
| state=retry_state, | ||
| request=retry_request, | ||
| response=retry_response, | ||
| ): | ||
| if logger.level <= logging.DEBUG: | ||
| logger.info(f"A retry handler found: {type(handler).__name__} for {http_verb} {api_url}") | ||
| await handler.prepare_for_next_attempt_async( | ||
| state=retry_state, | ||
| request=retry_request, | ||
| response=retry_response, | ||
| ) | ||
| break | ||
|
|
||
| if retry_state.next_attempt_requested is False: | ||
| response = { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from typing import List, Optional | ||
|
|
||
| from aiohttp import ClientResponseError | ||
|
|
||
| from slack_sdk.http_retry.builtin_async_handlers import AsyncServerErrorRetryHandler | ||
| from slack_sdk.http_retry.builtin_interval_calculators import FixedValueRetryIntervalCalculator | ||
| from slack_sdk.http_retry.state import RetryState | ||
| from slack_sdk.http_retry.request import HttpRequest | ||
| from slack_sdk.http_retry.response import HttpResponse | ||
|
|
||
|
|
||
| class ErrorRecordingRetryHandler(AsyncServerErrorRetryHandler): | ||
| def __init__(self): | ||
| super().__init__(max_retry_count=1, interval_calculator=FixedValueRetryIntervalCalculator(0)) | ||
| self.can_retry_errors: List[Optional[Exception]] = [] | ||
| self.prepare_errors: List[Optional[Exception]] = [] | ||
|
|
||
| async def _can_retry_async( | ||
| self, | ||
| *, | ||
| state: RetryState, | ||
| request: HttpRequest, | ||
| response: Optional[HttpResponse] = None, | ||
| error: Optional[Exception] = None, | ||
| ) -> bool: | ||
| self.can_retry_errors.append(error) | ||
| return await super()._can_retry_async(state=state, request=request, response=response, error=error) | ||
|
|
||
| async def prepare_for_next_attempt_async( | ||
| self, | ||
| *, | ||
| state: RetryState, | ||
| request: HttpRequest, | ||
| response: Optional[HttpResponse] = None, | ||
| error: Optional[Exception] = None, | ||
| ) -> None: | ||
| self.prepare_errors.append(error) | ||
| await super().prepare_for_next_attempt_async(state=state, request=request, response=response, error=error) | ||
|
|
||
|
|
||
| def error_statuses(errors: List[Optional[Exception]]) -> List[object]: | ||
| return [error.status if isinstance(error, ClientResponseError) else error for error in errors] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
suggestion (blocking): This also skips
ClientHttpProxyErrorandTooManyRedirects, which aiohttp raises before any response exists, soerror_types=[aiohttp.ClientError]stops retrying proxy errors it retries today. Could we match the sync handler and only skip when there's a response?