From ef22144854f0248163ff9250060ed49afff23bdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?d=20=F0=9F=94=B9?= <258577966+voidborne-d@users.noreply.github.com> Date: Tue, 17 Mar 2026 18:07:15 +0000 Subject: [PATCH] address P2 feedback: add lock docstring warning, remove redundant mock write - Add WARNING docstring to _get_shared_session_lock() about not resetting the lock to None while coroutines may be in the recovery path - Remove redundant proxy_server_module.shared_aiohttp_session assignment in mock_init (add_shared_session_to_data overwrites it synchronously) --- litellm/proxy/route_llm_request.py | 7 ++++++- tests/test_litellm/proxy/test_aiohttp_session_recovery.py | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/route_llm_request.py b/litellm/proxy/route_llm_request.py index 96e6f705cca..79e8f41972f 100644 --- a/litellm/proxy/route_llm_request.py +++ b/litellm/proxy/route_llm_request.py @@ -128,7 +128,12 @@ _shared_session_lock: Optional[asyncio.Lock] = None def _get_shared_session_lock() -> asyncio.Lock: - """Lazily create the shared session lock (must be called within a running event loop).""" + """Lazily create the shared session lock (must be called within a running event loop). + + WARNING: Do not reset _shared_session_lock to None while any coroutine may be + executing the session-recovery path; doing so breaks the double-checked locking + guarantee and can cause duplicate session creation. + """ global _shared_session_lock if _shared_session_lock is None: _shared_session_lock = asyncio.Lock() diff --git a/tests/test_litellm/proxy/test_aiohttp_session_recovery.py b/tests/test_litellm/proxy/test_aiohttp_session_recovery.py index 224a4aa1392..a2b09527962 100644 --- a/tests/test_litellm/proxy/test_aiohttp_session_recovery.py +++ b/tests/test_litellm/proxy/test_aiohttp_session_recovery.py @@ -161,7 +161,6 @@ async def test_add_shared_session_concurrent_recreation_uses_lock(): call_count += 1 # Simulate some async work await asyncio.sleep(0.01) - proxy_server_module.shared_aiohttp_session = new_session return new_session with patch.object(