From 1bffd71e7b3f78b4b6b02fca046cb137e97a4088 Mon Sep 17 00:00:00 2001 From: h Date: Sun, 25 Jan 2026 16:52:15 +0100 Subject: [PATCH] fix(backend): add async lock to prevent Already borrowed issue --- backend/src/utils/convex/client.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/src/utils/convex/client.py b/backend/src/utils/convex/client.py index 90b655d..731aba1 100644 --- a/backend/src/utils/convex/client.py +++ b/backend/src/utils/convex/client.py @@ -7,15 +7,19 @@ from convex import ConvexClient as SyncConvexClient class ConvexClient: def __init__(self, url: str) -> None: self._client = SyncConvexClient(url) + self._lock = asyncio.Lock() async def query(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401 - return await asyncio.to_thread(self._client.query, name, args or {}) + async with self._lock: + return await asyncio.to_thread(self._client.query, name, args or {}) async def mutation(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401 - return await asyncio.to_thread(self._client.mutation, name, args or {}) + async with self._lock: + return await asyncio.to_thread(self._client.mutation, name, args or {}) async def action(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401 - return await asyncio.to_thread(self._client.action, name, args or {}) + async with self._lock: + return await asyncio.to_thread(self._client.action, name, args or {}) def subscribe(self, name: str, args: dict[str, Any] | None = None) -> Any: # noqa: ANN401 return self._client.subscribe(name, args or {})