fix(mcp): catch RuntimeError when canceling tasks on closed event loop during /exit - #60205
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(mcp): catch RuntimeError when canceling tasks on closed event loop during /exit#60205liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
…p during /exit When calling /exit, MCP server tasks still running in _wait_for_reconnect_or_shutdown call t.cancel() -> call_soon() after the event loop is closed, causing RuntimeError exceptions. Move t.cancel() inside the try block and catch RuntimeError alongside CancelledError. This silences the 'Exception ignored' noise without changing functional behavior (the exceptions were already being caught and ignored). Fixes NousResearch#60197
Collaborator
Contributor
Author
|
Thanks @alt-glitch for the duplicate detection. After comparing the diffs:
Since #60032 is earlier and provides the same fix with minimal code changes, maintainers should merge #60032 instead. Closing this PR as a duplicate. |
This was referenced Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Catches
RuntimeErrorwhen canceling MCP server tasks on a closed event loop during/exit. When calling/exit, the shutdown sequence closes the asyncio event loop, but MCP tasks still running in_wait_for_reconnect_or_shutdowncallt.cancel()→call_soon(), causingRuntimeError: Event loop is closedexceptions that are printed as "Exception ignored" noise.The fix moves
t.cancel()inside the try block and catchesRuntimeErroralongsideCancelledError. This silences the noise without changing functional behavior (the exceptions were already being caught and ignored).Related Issue
Fixes #60197
Type of Change
Changes Made
tools/mcp_tool.py: Movet.cancel()inside the try block and catchRuntimeErroralongsideCancelledErrorin two locations (line 1837 and 1882)How to Test
python -m pytest tests/tools/test_mcp_tool.py -q/exiton an MCP-enabled session no longer emits "Exception ignored" RuntimeError noiseChecklist
Code
pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AFor New Skills