Skip to content

Commit d1e3931

Browse files
committed
fix: close_client race -- acquire _client_lock, null under lock, close outside
1 parent dc70c70 commit d1e3931

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

mcp-server/api_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ async def api_post(path: str, json: dict, **kwargs: Any) -> dict:
6161
async def close_client() -> None:
6262
"""Close the persistent client. Call on server shutdown."""
6363
global _client
64-
if _client and not _client.is_closed:
65-
await _client.aclose()
64+
async with _client_lock:
65+
local = _client
6666
_client = None
67+
if local and not local.is_closed:
68+
await local.aclose()

0 commit comments

Comments
 (0)