mirror of
https://github.com/turnstonelabs/turnstone.git
synced 2026-08-12 23:12:23 -06:00
fix: guard against CancelledError on MCP startup future (Python 3.14) (#146)
On Python 3.14, Future.exception() raises CancelledError on cancelled futures instead of returning None. Check future.cancelled() before calling exception() to prevent crash when the MCP event loop shuts down before _connect_all completes.
This commit is contained in:
@@ -162,9 +162,11 @@ class MCPClientManager:
|
||||
future = asyncio.run_coroutine_threadsafe(self._connect_all(), self._loop)
|
||||
self._connected.wait(timeout=30)
|
||||
# Surface any exception from _connect_all (unlikely — per-server errors are caught)
|
||||
if future.done() and future.exception():
|
||||
self._error = str(future.exception())
|
||||
log.error("MCP initialization error: %s", self._error)
|
||||
if future.done() and not future.cancelled():
|
||||
exc = future.exception()
|
||||
if exc:
|
||||
self._error = str(exc)
|
||||
log.error("MCP initialization error: %s", self._error)
|
||||
|
||||
async def _connect_all(self) -> None:
|
||||
"""Connect to every configured server (runs on the background loop)."""
|
||||
|
||||
Reference in New Issue
Block a user