fix: add timeout to MCP tool future.result() to prevent indefinite bl…#840
Open
walker0643 wants to merge 1 commit intoQwenLM:mainfrom
Open
fix: add timeout to MCP tool future.result() to prevent indefinite bl…#840walker0643 wants to merge 1 commit intoQwenLM:mainfrom
walker0643 wants to merge 1 commit intoQwenLM:mainfrom
Conversation
…ocking Increase timeout for MCP tool execution to 60 seconds and handle TimeoutError.
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.
Bug:
MCPManagertool calls block indefinitely when MCP server hangsSummary
When an MCP server becomes unresponsive during a tool call, the
ToolClass.call()method inmcp_manager.pyblocks the calling thread indefinitely. This causes worker threads to remain permanently active, consuming CPU resources until the process is manually killed.Root Cause
In
create_tool_class(), the result of the async tool call future is awaited with no timeout:If the underlying MCP server stalls (slow HTTP request, hung subprocess, failed SSE connection, DNS/SSL issue, etc.) the coroutine in
execute_functionnever resolves, andfuture.result()waits indefinitely. The thread pool worker that called the tool is permanently blocked, and because it holds a reference to the event loop, it also prevents clean shutdown.Observed Symptoms
concurrent.futuresthread pool workers stuck in_workerand markedactivein process monitors indefinitelySIGKILLpy-spy dumpshows all active threads blocked insidefuture.result()with no further stack progressionFix
Add a
timeoutparameter tofuture.result()and cancel the future on timeout