diff --git a/litellm/llms/custom_httpx/aiohttp_transport.py b/litellm/llms/custom_httpx/aiohttp_transport.py index 5d66208d885..29ef38cfa5f 100644 --- a/litellm/llms/custom_httpx/aiohttp_transport.py +++ b/litellm/llms/custom_httpx/aiohttp_transport.py @@ -23,8 +23,6 @@ AIOHTTP_EXC_MAP: Dict = { aiohttp.ServerTimeoutError: httpx.TimeoutException, aiohttp.ConnectionTimeoutError: httpx.ConnectTimeout, aiohttp.SocketTimeoutError: httpx.ReadTimeout, - # Asyncio cancellation - map to retryable ConnectError to trigger retry logic - asyncio.CancelledError: httpx.ConnectError, # Proxy related exceptions aiohttp.ClientProxyConnectionError: httpx.ProxyError, # SSL related exceptions @@ -62,9 +60,10 @@ def map_aiohttp_exceptions() -> typing.Iterator[None]: try: yield except asyncio.CancelledError as exc: - # asyncio.CancelledError inherits from BaseException (not Exception) in Python 3.9+. - # Catch it explicitly before the Exception handler and map to a retryable - # ConnectError so the router can retry on alternative deployments. + # asyncio.CancelledError inherits from BaseException (not Exception) in Python 3.9+, + # so it bypasses the `except Exception` block below and must be caught explicitly. + # Map to ConnectError so the router treats it as a retryable connection failure + # and can failover to alternative deployments (e.g., during intermittent DNS issues). message = f"Request cancelled during DNS resolution or connection: {str(exc)}" raise httpx.ConnectError(message) from exc except Exception as exc: