From dd0b58cc6e2c92b600bbb6a509d128210594f4ab Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2026 20:00:02 +0000 Subject: [PATCH] chore(aiohttp): drop explanatory comments to satisfy repo comment policy --- litellm/llms/custom_httpx/aiohttp_transport.py | 9 --------- litellm/llms/custom_httpx/http_handler.py | 14 -------------- .../custom_httpx/test_aiohttp_so_keepalive.py | 17 ----------------- 3 files changed, 40 deletions(-) diff --git a/litellm/llms/custom_httpx/aiohttp_transport.py b/litellm/llms/custom_httpx/aiohttp_transport.py index 87355acca4c..9552d98eb34 100644 --- a/litellm/llms/custom_httpx/aiohttp_transport.py +++ b/litellm/llms/custom_httpx/aiohttp_transport.py @@ -165,20 +165,11 @@ class LiteLLMAiohttpTransport(AiohttpTransport): self.client = client self._ssl_verify = ssl_verify # Store for per-request SSL override super().__init__(client=client, owns_session=owns_session) - # Store the client factory for recreating sessions when needed. An - # explicit session_factory wins so a concrete `client` (e.g. a shared - # session) still recreates with keep-alive wiring instead of a bare - # ClientSession. self._client_factory: Callable[[], ClientSession] | None = ( session_factory if session_factory is not None else client if callable(client) else None ) def _new_session(self) -> ClientSession: - """ - Build a fresh ClientSession, preferring the stored factory (which - carries the SO_KEEPALIVE socket factory) and falling back to a - keep-alive-aware default rather than a bare aiohttp.ClientSession(). - """ if self._client_factory is not None: return self._client_factory() diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.py index e4e348b199f..b50baa4cefe 100644 --- a/litellm/llms/custom_httpx/http_handler.py +++ b/litellm/llms/custom_httpx/http_handler.py @@ -108,13 +108,6 @@ def _build_aiohttp_keepalive_socket_factory() -> Optional[Callable[[Tuple[Any, . def _build_aiohttp_transport_connector_kwargs( base_kwargs: dict[str, Any] | None = None, ) -> dict[str, Any]: - """ - Build the TCPConnector kwargs shared by every aiohttp session litellm - creates, so the SO_KEEPALIVE socket factory and pool tuning are applied - consistently across the AsyncHTTPHandler path and the OpenAI/Azure - aiohttp_transport fallbacks. socket_factory is only included when - keep-alive is enabled and aiohttp is new enough to accept it. - """ socket_factory = _build_aiohttp_keepalive_socket_factory() return { "keepalive_timeout": AIOHTTP_KEEPALIVE_TIMEOUT, @@ -128,13 +121,6 @@ def _build_aiohttp_transport_connector_kwargs( def build_default_aiohttp_client_session(trust_env: bool = False) -> ClientSession: - """ - Create a ClientSession backed by a keep-alive-aware TCPConnector. - - Used as the fallback session builder on the aiohttp_transport code path - (OpenAI/Azure) so recreated sessions still emit TCP keep-alive probes - instead of silently dropping back to a bare aiohttp.ClientSession(). - """ return ClientSession( connector=TCPConnector(**_build_aiohttp_transport_connector_kwargs()), trust_env=trust_env, diff --git a/tests/test_litellm/llms/custom_httpx/test_aiohttp_so_keepalive.py b/tests/test_litellm/llms/custom_httpx/test_aiohttp_so_keepalive.py index 48e4b87a222..6288c996e4b 100644 --- a/tests/test_litellm/llms/custom_httpx/test_aiohttp_so_keepalive.py +++ b/tests/test_litellm/llms/custom_httpx/test_aiohttp_so_keepalive.py @@ -164,19 +164,10 @@ def test_socket_factory_uses_tcp_keepalive_when_keepidle_unavailable(monkeypatch def _last_socket_factory(mock_tcp_connector): - """socket_factory kwarg of the most recent TCPConnector(...) construction.""" return mock_tcp_connector.call_args.kwargs.get("socket_factory") def test_shared_session_transport_recreates_with_socket_factory(monkeypatch): - """ - Regression for issue #33567: when the aiohttp transport is built around a - caller-provided shared ClientSession, it must still recreate stale sessions - (closed / cross-loop) through a keep-alive-aware factory. Before the fix the - shared-session transport stored no factory, so _get_valid_client_session - fell back to a bare aiohttp.ClientSession() with no socket_factory and - AIOHTTP_SO_KEEPALIVE had zero effect on the Azure/OpenAI path. - """ from litellm.llms.custom_httpx import http_handler as http_handler_module monkeypatch.setattr(http_handler_module, "AIOHTTP_SO_KEEPALIVE", True) @@ -197,9 +188,7 @@ def test_shared_session_transport_recreates_with_socket_factory(monkeypatch): transport = http_handler_module.AsyncHTTPHandler._create_aiohttp_transport( shared_session=shared_session ) - # Transport reuses the shared session as the live client... assert transport.client is shared_session - # ...but a keep-alive-aware factory backs every recreation. assert transport._client_factory is not None transport._new_session() @@ -208,18 +197,12 @@ def test_shared_session_transport_recreates_with_socket_factory(monkeypatch): def test_new_session_falls_back_to_keepalive_default(monkeypatch): - """ - A transport constructed with a concrete client and no factory must still - rebuild through the keep-alive-aware default rather than a bare session. - """ from litellm.llms.custom_httpx import http_handler as http_handler_module from litellm.llms.custom_httpx.aiohttp_transport import LiteLLMAiohttpTransport monkeypatch.setattr(http_handler_module, "AIOHTTP_SO_KEEPALIVE", True) monkeypatch.setattr(http_handler_module, "_AIOHTTP_SUPPORTS_SOCKET_FACTORY", True) - # A non-callable client stands in for a concrete ClientSession so no - # factory is inferred from it. concrete_session = object() transport = LiteLLMAiohttpTransport(client=concrete_session, session_factory=None) assert transport._client_factory is None