fix(core): remove pending response entries on request timeout and cancellation - #1134
Open
Lubaoshuai wants to merge 1 commit into
Open
Lubaoshuai wants to merge 1 commit into
Lubaoshuai wants to merge 1 commit into
Conversation
…cellation McpClientSession and McpServerSession left the pendingResponses entry in place when the downstream timeout fired or the caller cancelled, so each timed-out request leaked its entry forever (request IDs are unique). Mirror the doOnError/doOnCancel cleanup the streamable session variant already performs after .timeout(requestTimeout). Fixes modelcontextprotocol#1133
Lubaoshuai
force-pushed
the
fix/pending-response-timeout-leak
branch
from
September 13, 2026 18:03
b25d2cc to
9b8604e
Compare
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.
Fixes #1133
McpClientSession.sendRequestandMcpServerSession.sendRequestleft theirpendingResponsesentry in place when the downstream.timeout(...)fired or the caller cancelled — the entry was only removed on a response or a send failure. Since request IDs are unique per request, a timed-out request leaked its entry forever;KeepAliveSchedulerpings amplify this into one leaked entry per interval on sessions with a dead peer.Both methods now mirror the cleanup pattern already used by
McpStreamableServerSession.McpStreamableServerSessionStream.sendRequest:doOnError+doOnCancelremove the entry after the timeout boundary. Removal is idempotent, and a late response for a removed id already takes the existing "unexpected response" path.How verified
testRequestTimeoutRemovesPendingResponseinMcpClientSessionTests: a request against a 50 ms-timeout session is let expire, then thependingResponsesmap is asserted empty../mvnw -pl mcp-core testpasses locally.