mirror of
https://github.com/turnstonelabs/turnstone.git
synced 2026-08-20 11:00:59 -06:00
fix: add timeout to MCP server disconnect to prevent hung removals
stack.aclose() on a stuck streamable-http transport hangs indefinitely, causing 50% CPU on all nodes when removing a broken remote server via reconcile_sync. Wrap with asyncio.wait_for(timeout=10s) so cleanup proceeds even if the transport refuses to close cleanly.
This commit is contained in:
@@ -977,8 +977,10 @@ class MCPClientManager:
|
||||
self._sessions.pop(name, None)
|
||||
stack = self._per_server_stacks.pop(name, None)
|
||||
if stack is not None:
|
||||
with contextlib.suppress(Exception):
|
||||
await stack.aclose()
|
||||
try:
|
||||
await asyncio.wait_for(stack.aclose(), timeout=10)
|
||||
except (TimeoutError, Exception):
|
||||
log.warning("Timed out closing MCP server '%s', forcing cleanup", name)
|
||||
# Clean up per-server state (on the event loop thread)
|
||||
self._per_server_tools.pop(name, None)
|
||||
self._per_server_resources.pop(name, None)
|
||||
|
||||
Reference in New Issue
Block a user