mcp: fix concurrent request response collection race#299628
Merged
connor4312 merged 2 commits intomainfrom Mar 6, 2026
Merged
Conversation
- JsonRpcProtocol.handleMessage now returns JsonRpcMessage[] containing responses generated by incoming requests, rather than delegating response collection to callers via side-channel state - McpGatewaySession simplified by removing _pendingResponses and _isCollectingPostResponses fields, which were susceptible to racing under concurrent HTTP POSTs. Now directly uses handleMessage's return value for the response body - _send callback still invoked for all messages (backward compatible with McpServerRequestHandler and SSE notification broadcast) - Updated tests to assert on handleMessage return values Fixes #297780 (Commit message generated by Copilot)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes side-channel response collection to fix a race when concurrent HTTP POSTs are processed, by having JsonRpcProtocol.handleMessage return the response message(s) generated while handling incoming requests.
Changes:
JsonRpcProtocol.handleMessagenow returnsJsonRpcMessage[]containing generated responses.McpGatewaySessionno longer uses_pendingResponses/_isCollectingPostResponsesand instead returnshandleMessage’s replies directly.- Tests updated to assert on
handleMessagereturn values.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/vs/platform/mcp/node/mcpGatewaySession.ts | Removes racy side-channel response collection and uses returned replies. |
| src/vs/base/common/jsonRpcProtocol.ts | Changes protocol API to return generated reply messages while still calling _send. |
| src/vs/base/test/common/jsonRpcProtocol.test.ts | Updates assertions to validate handleMessage reply arrays. |
You can also share your feedback on Copilot code review. Take the survey.
- Adds JSDoc to handleMessage clarifying what is returned (only responses for incoming requests), ordering guarantees for batch inputs, and that responses are still emitted via _send callback to avoid double-sending - Tightens _handleRequest return type from Promise<JsonRpcMessage> to Promise<JsonRpcResponse>, enforcing that only valid responses are returned. Introduces JsonRpcResponse type alias for better type safety - Expands error handling tests to assert that returned replies match what is emitted via _send for both JsonRpcError and generic error paths Fixes #297780 (Commit message generated by Copilot)
rzhao271
approved these changes
Mar 6, 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.
responses generated by incoming requests, rather than delegating
response collection to callers via side-channel state
_isCollectingPostResponses fields, which were susceptible to racing
under concurrent HTTP POSTs. Now directly uses handleMessage's
return value for the response body
with McpServerRequestHandler and SSE notification broadcast)
Fixes #297780
(Commit message generated by Copilot)