Repository navigation
Fixes #1174 - #1175
Open
kamisheng wants to merge 1 commit into
Open
Fixes #1174#1175kamisheng wants to merge 1 commit into
kamisheng wants to merge 1 commit into
Conversation
The Mono returned by listTools, listResources, listResourceTemplates,
listPrompts and listRoots captured a single mutable accumulator created when
the method was called, so every subscription kept appending to it:
Mono<ListRootsResult> listRoots = exchange.listRoots();
listRoots.block().roots().size(); // 2
listRoots.block().roots().size(); // 4
listRoots.block().roots().size(); // 6
Concurrent subscriptions also raced on the shared ArrayList.
Use reduceWith(Supplier, accumulator) so that a fresh accumulator is created
for every subscription. A single subscription behaves exactly as before.
This branch has not been deployed
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.
Motivation and Context
The Mono returned by
listTools,listResources,listResourceTemplates,listPromptsand
listRootsis not safe to subscribe more than once:reduce(seed, accumulator)captures one mutable seed instance created when the method is called, so every
subscription keeps appending to it.
Concurrent subscriptions also race on the shared
ArrayList.Description
Replaced
reduce(seed, accumulator)withreduceWith(Supplier, accumulator)at the fivecall sites, so a fresh accumulator is created per subscription. Behavior for a single
subscription is unchanged.
Fixes #1174
How Has This Been Tested?
McpAsyncServerExchangeTests#testListRootsCanBeResubscribed, which subscribes thesame Mono twice and asserts both subscriptions see the same number of roots. It fails
before the change (2 then 4) and passes after.
AbstractMcpAsyncClientTests, which runsagainst the SSE, stdio and Streamable HTTP transports.
./mvnw -pl mcp-core spring-javaformat:apply./mvnw -pl mcp-core test(73 tests in the affected classes pass)Types of changes