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)
This commit is contained in:
d 🔹 2026-03-17 18:07:15 +00:00
parent 32ecd24116
commit ef22144854
2 changed files with 6 additions and 2 deletions

View file

@ -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()

View file

@ -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(