mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
chore(aiohttp): drop explanatory comments to satisfy repo comment policy
This commit is contained in:
parent
bed3fe4ac0
commit
dd0b58cc6e
3 changed files with 0 additions and 40 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue