fix: use Mono.when instead of Mono.zip for stdio readiness signals - #987
Closed
k-krawczyk wants to merge 1 commit into
Closed
k-krawczyk wants to merge 1 commit into
k-krawczyk wants to merge 1 commit into
Conversation
StdioServerTransportProvider.sendMessage waited on inbound/outbound readiness with Mono.zip. Both inboundReady and outboundReady are Sinks.One<Void> that complete empty (tryEmitValue(null)), and Mono.zip requires every source to emit a value: when one source completes empty it short-circuits and cancels the others. As a result sendMessage could proceed before both streams were actually ready instead of waiting for both. Mono.when subscribes to all sources and completes only once all of them complete, which is the correct combinator for completion-only (Mono<Void>) signals. Fixes modelcontextprotocol#303
Author
|
Closing — already fixed by another contributor. |
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.
Summary
Fixes #303.
StdioServerTransportProvider.sendMessagewaited for the inbound and outbound streams to be ready usingMono.zip:Both
inboundReadyandoutboundReadyareSinks.One<Void>that complete empty (tryEmitValue(null)).Mono.ziprequires every source to emit a value, and when one source completes without a value it short-circuits and cancels the remaining sources — exactly the behavior IntelliJ flagged in the issue. The consequence is thatsendMessagecould proceed as soon as the first readiness signal fired, cancelling the wait on the other, rather than waiting for both streams.Mono.whenis the correct combinator for completion-only (Mono<Void>) signals: it subscribes to all sources and completes only once all of them complete.This matches the analysis and the reproduction in the issue.
Change
One-line operator swap:
Mono.zip→Mono.when.Testing
mcp-corecompiles cleanly.StdioServerTransportProviderTests(9 tests) pass.