Skip to content

Commit fc539a5

Browse files
committed
fix: add fallback cleanup when event loop is not running
Added else branch to handle edge case where loop exists but is not running. Uses asyncio.run() as fallback to ensure cleanup happens even if the loop was stopped externally or due to an error.
1 parent 99efbe0 commit fc539a5

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

core/framework/runner/mcp_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,13 @@ def disconnect(self) -> None:
420420

421421
# Now stop the event loop
422422
self._loop.call_soon_threadsafe(self._loop.stop)
423+
else:
424+
# Fallback: loop exists but not running (e.g., due to error or external stop)
425+
# Use asyncio.run() to execute cleanup in a new event loop
426+
try:
427+
asyncio.run(self._cleanup_stdio_async())
428+
except Exception as e:
429+
logger.warning(f"Error during fallback async cleanup: {e}")
423430

424431
# Wait for thread to finish
425432
if self._loop_thread and self._loop_thread.is_alive():

0 commit comments

Comments
 (0)