[v6.0] fix: MCP callTool hangs and leaks its response handler when an in-flight request is aborted#16794
Merged
Merged
Conversation
…ght request is aborted (#16595) ## Background Aborting a slow or hung MCP tool call after the JSON-RPC request was sent left the callTool promise pending and kept its response handler registered indefinitely. ## Summary DefaultMCPClient.request now registers an abort listener for in-flight requests and consistently cleans up the response handler and abort listener when the request aborts, responds, fails to send, or fails response parsing. ## Testing Added a regression test with a custom hanging MCP transport that verifies an aborted in-flight tool call rejects with MCPClientError and clears responseHandlers. ## Related Issues Fixes #16580 Co-authored-by: Abuhaithem <107338221+Abuhaithem@users.noreply.github.com> (cherry picked from commit 3e6e955)
v6's callTool takes { name, args, options: ToolExecutionOptions } and
is not declared on the public MCPClient interface, so the test uses a
structural cast and passes abortSignal instead of main's
{ arguments, options: { signal } } shape.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
Author
|
Follow-up commit: adapted the new regression test to v6's |
Contributor
|
|
Contributor
|
🚀 Published in:
|
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.
Backport of #16595 to
release-v6.0(clean cherry-pick). v6mcp-client.tshas the identical pattern (abort only checked inside the response handler, no abort listener/cleanup). Includes the regression test with a hanging transport.Part of the v6.0 backport tracking issue #16767.