From 7b00120f05d081c9c8280fa2ac048dc8efb09f8b Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Tue, 24 Mar 2026 13:37:55 +0800 Subject: [PATCH] fix: explicitly propagate asyncio.CancelledError in aiohttp transport/handler (issue #22100) --- litellm/llms/custom_httpx/aiohttp_handler.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/litellm/llms/custom_httpx/aiohttp_handler.py b/litellm/llms/custom_httpx/aiohttp_handler.py index 93b6c563dc1..dae275885ec 100644 --- a/litellm/llms/custom_httpx/aiohttp_handler.py +++ b/litellm/llms/custom_httpx/aiohttp_handler.py @@ -1,3 +1,4 @@ +import asyncio from typing import TYPE_CHECKING, Any, Callable, Optional, Tuple, Union, cast import aiohttp @@ -204,6 +205,12 @@ class BaseLLMAIOHTTPHandler: except aiohttp.ClientResponseError as e: setattr(e, "text", e.message) raise self._handle_error(e=e, provider_config=provider_config) + except asyncio.CancelledError: + # CancelledError is a BaseException in Python 3.8+, so it won't + # be caught by `except Exception`. Re-raise explicitly so that + # task-cancellation propagates correctly instead of being silently + # swallowed or bypassing retry/logging logic. See issue #22100. + raise except Exception as e: raise self._handle_error(e=e, provider_config=provider_config) break