From 3737af0cf5b3d6d7c75372e14014fa712a82df64 Mon Sep 17 00:00:00 2001 From: disqualifier Date: Mon, 29 Jun 2026 20:47:55 -0400 Subject: [PATCH] fix: total-timeout labeled 'timeout' in request_with_retries (dead branch live) (v0.1.5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AW-1: request() wraps a total ClientTimeout's bare asyncio.TimeoutError before request_with_retries sees it, so the dedicated 'timeout' branch was dead and its comment lied. wrap it as aiohttp.ServerTimeoutError (which IS both a ClientError AND a TimeoutError) so direct request() callers still get a typed failure (M1 preserved) while request_with_retries catches the timeout case first and labels it 'timeout'. verified by execution: request() raises ServerTimeoutError (typed, M1 intact); request_with_retries returns reason='timeout'; control confirms a real client error still labels 'client error'. sibling-grep: aioweb_tls/aiowebhooks catch ClientError/TimeoutError, both of which ServerTimeoutError satisfies — no consumer break. Signed-off-by: disqualifier --- README.md | 6 +++--- pyproject.toml | 2 +- src/aioweb/session.py | 20 ++++++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4f340ff..5a9804c 100644 --- a/README.md +++ b/README.md @@ -11,18 +11,18 @@ and swap the HTTP client while inheriting everything else. `requirements.txt`: ``` -aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.4 +aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.5 ``` Direct: ```bash -pip install "aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.4" +pip install "aioweb @ git+ssh://git@git.rethinkstudios.io/rethink-public/aioweb.git@v0.1.5" ``` Requires `aiohttp` and `yarl` (pulled transitively). -Drop the `@v0.1.4` suffix from the line above to install the latest unpinned. +Drop the `@v0.1.5` suffix from the line above to install the latest unpinned. ## Usage diff --git a/pyproject.toml b/pyproject.toml index 0105226..d76b2a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "aioweb" -version = "0.1.4" +version = "0.1.5" description = "Async HTTP session wrapper over aiohttp — proxies, header overwrites, retries, previews. Config-free, installable." requires-python = ">=3.10" dependencies = [ diff --git a/src/aioweb/session.py b/src/aioweb/session.py index 0f1a185..d9ee9ab 100644 --- a/src/aioweb/session.py +++ b/src/aioweb/session.py @@ -316,10 +316,13 @@ class ExtendedSession: if debug and result.redirect_chain: log.info("redirect chain: %s", result.redirect_chain) return result - except (aiohttp.ClientError, asyncio.TimeoutError) as error: + except asyncio.TimeoutError as error: # a total ClientTimeout raises a bare asyncio.TimeoutError, which is NOT an - # aiohttp.ClientError subclass — wrap it into the same typed path so direct - # callers get a consistent failure instead of a raw timeout + # aiohttp.ClientError subclass — wrap it as ServerTimeoutError (which IS both + # a ClientError AND a TimeoutError) so direct callers get a typed failure and + # request_with_retries can still label it a timeout + raise aiohttp.ServerTimeoutError(f"timeout for {url}: {error}") from error + except aiohttp.ClientError as error: raise aiohttp.ClientError(f"client error for {url}: {error}") from error async def request_with_retries( @@ -364,14 +367,15 @@ class ExtendedSession: log.error("all %d attempts failed for %s (last status %s)", attempts, url, exhausted.response.status_code) return exhausted.response + except asyncio.TimeoutError: + # request() wraps a total timeout as ServerTimeoutError (a ClientError AND a + # TimeoutError); catch the timeout case first so it's labeled a timeout rather + # than falling into the generic client-error branch below + log.error("all %d attempts timed out for %s", attempts, url) + return FailureResponse(reason="timeout", url=url) except aiohttp.ClientError as error: log.error("all %d attempts failed for %s (client error: %s)", attempts, url, error) return FailureResponse(reason=f"client error: {error}", url=url) - except asyncio.TimeoutError: - # a total ClientTimeout surfaces as a bare asyncio.TimeoutError; label it as - # a timeout rather than letting it fall to the generic "unexpected" branch - log.error("all %d attempts timed out for %s", attempts, url) - return FailureResponse(reason="timeout", url=url) except Exception as error: log.error("all %d attempts failed for %s (unexpected: %s)", attempts, url, error) return FailureResponse(reason=f"unexpected error: {error}", url=url)