fix(proxy): restore conditional aiohttp connector kwargs omission

The simplification in the prior commit always passed enable_cleanup_closed,
limit, limit_per_host, and socket_factory to TCPConnector, whereas the
original code only included each key when it was actually needed. Restore
the conditional dict-building so callers/tests observing the exact kwargs
(e.g. asserting enable_cleanup_closed is absent when not needed) still pass.

Caught by CI: tests/test_litellm/proxy/test_aiohttp_cleanup_closed.py.
This commit is contained in:
mateo-berri 2026-07-30 11:19:15 +00:00
parent fee80d6c5f
commit 4a11474fcf
No known key found for this signature in database
3 changed files with 29 additions and 22 deletions

View file

@ -1,9 +1,9 @@
{
"reportAny": {
"limit": 32379
"limit": 32138
},
"reportArgumentType": {
"limit": 2633
"limit": 2629
},
"reportAssignmentType": {
"limit": 329
@ -24,7 +24,7 @@
"limit": 42
},
"reportExplicitAny": {
"limit": 9602
"limit": 9394
},
"reportFunctionMemberAccess": {
"limit": 11
@ -54,10 +54,10 @@
"limit": 0
},
"reportMissingParameterType": {
"limit": 5857
"limit": 5853
},
"reportMissingTypeArgument": {
"limit": 15831
"limit": 15820
},
"reportMissingTypeStubs": {
"limit": 41
@ -99,19 +99,19 @@
"limit": 0
},
"reportUnknownArgumentType": {
"limit": 45456
"limit": 45435
},
"reportUnknownLambdaType": {
"limit": 113
},
"reportUnknownMemberType": {
"limit": 40416
"limit": 40396
},
"reportUnknownParameterType": {
"limit": 20296
"limit": 20281
},
"reportUnknownVariableType": {
"limit": 31976
"limit": 31952
},
"reportUnnecessaryCast": {
"limit": 177

View file

@ -839,14 +839,21 @@ async def _initialize_shared_aiohttp_session():
_build_aiohttp_keepalive_socket_factory,
)
connector = TCPConnector(
keepalive_timeout=AIOHTTP_KEEPALIVE_TIMEOUT,
ttl_dns_cache=AIOHTTP_TTL_DNS_CACHE,
enable_cleanup_closed=AIOHTTP_NEEDS_CLEANUP_CLOSED,
limit=AIOHTTP_CONNECTOR_LIMIT if AIOHTTP_CONNECTOR_LIMIT > 0 else 100,
limit_per_host=AIOHTTP_CONNECTOR_LIMIT_PER_HOST if AIOHTTP_CONNECTOR_LIMIT_PER_HOST > 0 else 0,
socket_factory=_build_aiohttp_keepalive_socket_factory(),
)
connector_kwargs: Dict[str, Any] = {
"keepalive_timeout": AIOHTTP_KEEPALIVE_TIMEOUT,
"ttl_dns_cache": AIOHTTP_TTL_DNS_CACHE,
}
if AIOHTTP_NEEDS_CLEANUP_CLOSED:
connector_kwargs["enable_cleanup_closed"] = True
if AIOHTTP_CONNECTOR_LIMIT > 0:
connector_kwargs["limit"] = AIOHTTP_CONNECTOR_LIMIT
if AIOHTTP_CONNECTOR_LIMIT_PER_HOST > 0:
connector_kwargs["limit_per_host"] = AIOHTTP_CONNECTOR_LIMIT_PER_HOST
socket_factory = _build_aiohttp_keepalive_socket_factory()
if socket_factory is not None:
connector_kwargs["socket_factory"] = socket_factory
connector = TCPConnector(**connector_kwargs)
session = ClientSession(connector=connector)
verbose_proxy_logger.info(

View file

@ -1,6 +1,6 @@
{
"ANN001": {
"limit": 3106
"limit": 3102
},
"ANN002": {
"limit": 69
@ -24,7 +24,7 @@
"limit": 130
},
"ANN401": {
"limit": 1821
"limit": 1757
},
"ASYNC230": {
"limit": 14
@ -222,7 +222,7 @@
"limit": 38
},
"RET504": {
"limit": 713
"limit": 712
},
"RUF010": {
"limit": 874
@ -306,7 +306,7 @@
"limit": 9
},
"TID251": {
"limit": 2649
"limit": 2648
},
"TRY002": {
"limit": 547
@ -363,6 +363,6 @@
"limit": 105
},
"UP045": {
"limit": 17788
"limit": 17770
}
}