fix(cache): lazy-init TTL cache locks to survive event-loop turnover
A module-level asyncio.Lock binds to the loop it was first awaited on. Under pytest-anyio (and xdist) each test spins up a new loop; any later test that hit /health or /config would wait on a lock owned by a dead loop and the whole worker would hang. Create the lock on first use and drop it in the test-reset helpers so a fresh loop always gets a fresh lock.
This commit is contained in:
@@ -24,6 +24,9 @@ _state_locks: dict[str, asyncio.Lock] = {}
|
||||
def _reset_state_cache() -> None:
|
||||
"""Reset cached config state — used by tests."""
|
||||
_state_cache.clear()
|
||||
# Drop any locks bound to the previous event loop — reusing one from
|
||||
# a dead loop deadlocks the next test.
|
||||
_state_locks.clear()
|
||||
|
||||
|
||||
async def _get_state_cached(name: str) -> Optional[dict[str, Any]]:
|
||||
|
||||
Reference in New Issue
Block a user