Skip to content

fix: use Mono.when instead of Mono.zip for stdio readiness signals - #987

Closed
k-krawczyk wants to merge 1 commit into
modelcontextprotocol:mainfrom
k-krawczyk:fix/stdio-mono-when-303
Closed

k-krawczyk wants to merge 1 commit into
modelcontextprotocol:mainfrom
k-krawczyk:fix/stdio-mono-when-303

Conversation

@k-krawczyk

Copy link
Copy Markdown

Summary

Fixes #303.

StdioServerTransportProvider.sendMessage waited for the inbound and outbound streams to be ready using Mono.zip:

return Mono.zip(inboundReady.asMono(), outboundReady.asMono()).then(Mono.defer(() -> { ... }));

Both inboundReady and outboundReady are Sinks.One<Void> that complete empty (tryEmitValue(null)). Mono.zip requires 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 that sendMessage could proceed as soon as the first readiness signal fired, cancelling the wait on the other, rather than waiting for both streams.

Mono.when is 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-core compiles cleanly.
  • Existing StdioServerTransportProviderTests (9 tests) pass.

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
@k-krawczyk

Copy link
Copy Markdown
Author

Closing — already fixed by another contributor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StdioServerTransportProvider uses incorrect Mono.zip operator

1 participant