Skip to content

fix(mcp): move t.cancel() inside try block to prevent RuntimeError on exit (#60197) - #60213

Closed
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/60197-eventloop-exit
Closed

fix(mcp): move t.cancel() inside try block to prevent RuntimeError on exit (#60197)#60213
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/60197-eventloop-exit

Conversation

@webtecnica

Copy link
Copy Markdown
Contributor

Fix RuntimeError when /exit is called with MCP tasks running. Moved t.cancel() inside try block at both cleanup locations. Closes #60197

… /exit

During shutdown, the event loop is closed before MCP tasks finish, so
t.cancel() → call_soon() raises RuntimeError('Event loop is closed').
Moved t.cancel() inside the try block at both locations (keepalive
loop and _wait_for_reconnect_or_shutdown).

Closes NousResearch#60197
@webtecnica

Copy link
Copy Markdown
Contributor Author

@teknium1 Clean shutdown — no more RuntimeError noise on /exit with MCP tasks. 8 lines in mcp_tool.py. Closes #60197. 🙏

@alt-glitch alt-glitch added type/bug Something isn't working comp/tools Tool registry, model_tools, toolsets tool/mcp MCP client and OAuth duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists labels Jul 7, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.
Duplicate of #60032 (earliest open, same two t.cancel() sites in _wait_for_reconnect_or_shutdown, same fix: cancel inside try + catch RuntimeError). Sibling #60205 is the same mechanism; #60104 takes a different approach (drain parked tasks before closing the loop). All target #60197 — maintainer picks between #60032/#60205 (narrow catch) and #60104 (lifecycle drain).

@webtecnica

Copy link
Copy Markdown
Contributor Author

Closing as duplicate — the sweeper identified this as already covered by another PR. Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] RuntimeError: Event loop is closed during /exit (MCPServerTask.shutdown)

2 participants