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:
Patrick Buckley
2026-03-15 21:42:05 -07:00
parent ef6cac6428
commit df8a36ced4
+4 -2
View File
@@ -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)