Repository navigation
fix(web, audit_logs, scim, webhook): pass the status error to async retry handlers - #2080
WilliamBergamin wants to merge 3 commits into
Conversation
…etry handlers On an error status the sync clients hand retry handlers the urllib HTTPError, but the async clients passed no error at all. They now pass an aiohttp ClientResponseError built from the response, and AsyncConnectionErrorRetryHandler skips it the way the sync handler skips HTTPError. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2080 +/- ##
==========================================
+ Coverage 84.69% 84.73% +0.04%
==========================================
Files 118 118
Lines 14116 14131 +15
==========================================
+ Hits 11955 11974 +19
+ Misses 2161 2157 -4 ☔ View full report in Codecov by Harness. |
Let aiohttp raise the ClientResponseError itself, the way urllib raises HTTPError for the sync clients, instead of rebuilding it by hand. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…r like sync Drop the _status_error helper. Each async client now calls res.raise_for_status() and runs its retry handlers in an except aiohttp.ClientResponseError branch, mirroring the sync clients' except HTTPError branch. WebClient keeps a separate handler loop for successful responses, as the sync BaseClient does. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
mwbrooks
left a comment
There was a problem hiding this comment.
One blocking point: the new ClientResponseError skip in the connection handler also drops retries for proxy and redirect errors. Once it matches the sync check, this is an approve from me.
| if error is None or isinstance(error, ClientResponseError): | ||
| return False |
There was a problem hiding this comment.
suggestion (blocking): This also skips ClientHttpProxyError and TooManyRedirects, which aiohttp raises before any response exists, so error_types=[aiohttp.ClientError] stops retrying proxy errors it retries today. Could we match the sync handler and only skip when there's a response?
| if error is None or isinstance(error, ClientResponseError): | |
| return False | |
| if error is None: | |
| return False | |
| if isinstance(error, ClientResponseError) and response is not None: | |
| return False # status 4xx/5xx |
| 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: |
There was a problem hiding this comment.
suggestion (non-blocking): The two handler loops only differ by error=e, so we could start with error = None, assign it in the except, and keep one loop that passes error=error. One copy is easier to keep in step with the other three clients.
Summary
This pull request passes an error to async retry handlers on an HTTP error status, as the sync clients already do.
can_retry/prepare_for_next_attemptwith the urllibHTTPError, but the asyncWebClient,AuditLogsClient,SCIMClientandWebhookClientpassed noerror, so handlers sawNone. Left over from fix(audit_logs, scim, webhook): retry async calls on any error status #2061.aiohttp.ClientResponseErrorthatres.raise_for_status()raises, the way urllib raisesHTTPErrorfor the sync clients.WebClientstill passesNonefor responses under 400.AsyncConnectionErrorRetryHandlernow skipsClientResponseError, mirroring the sync handler'sHTTPErrorcheck, soerror_types=[aiohttp.ClientError]does not start retrying every 4xx.Noneerroron error statuses. A handler that retries on any non-Noneerror will now retry status errors, as it already does on sync. Worth a line in the release notes.Testing
Each async
*_http_retrysuite gets a test that hits the mock 500 endpoint and checks both handler methods receive aClientResponseErrorwithstatus == 500. They fail onmainand pass here.tests/slack_sdk_async/http_retry/test_builtins.pychecks the connection handler skips a status error even whenerror_typesincludesaiohttp.ClientError.Category
/docs(Documents)/tutorial(PythOnBoardingBot tutorial)tests/integration_tests(Automated tests for this library)Requirements
python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.🤖 Generated with Claude Code