The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: prevent session leaks when recreating aiohttp sessions (#15443)
Alexsander Hamir0374fe02f7eb
diff --git a/litellm/llms/custom_httpx/aiohttp_transport.py b/litellm/llms/custom_httpx/aiohttp_transport.pyindex da196e2e1e8..50bbccd6a4b 100644--- a/litellm/llms/custom_httpx/aiohttp_transport.py+++ b/litellm/llms/custom_httpx/aiohttp_transport.py@@ -179,14 +179,17 @@ class LiteLLMAiohttpTransport(AiohttpTransport):or session_loop != current_loopor session_loop.is_closed()):- # Clean up the old session+ # Close old session to prevent leaks+ old_session = self.clienttry:- # Note: not awaiting close() here as it might be from a different loop- # The session will be garbage collected- pass+ if not old_session.closed:+ try:+ asyncio.create_task(old_session.close())+ except RuntimeError:+ # Different event loop - can't schedule task, rely on GC+ verbose_logger.debug("Old session from different loop, relying on GC")except Exception as e:verbose_logger.debug(f"Error closing old session: {e}")- pass# Create a new session in the current event loopif hasattr(self, "_client_factory") and callable(self._client_factory):