Skip to content

fix: race condition in ResponseSubscribers - #1152

Open
nickcaballero wants to merge 1 commit into
modelcontextprotocol:2.0.xfrom
nickcaballero:fix/response-subscribers-race
Open

nickcaballero wants to merge 1 commit into
modelcontextprotocol:2.0.xfrom
nickcaballero:fix/response-subscribers-race

Conversation

@nickcaballero

@nickcaballero nickcaballero commented Sep 30, 2026 •

Copy link
Copy Markdown

Motivation and Context

This PR fixes a race condition in the io.modelcontextprotocol.client.transport.ResponseSubscribers. The root of the issue is that AggregateSubscriber and BodilessResponseLineSubscriber use a flag to determine if data was requested, but the flag is set after propagating the request to the source subscription. If the source subscription emits the requested data on the calling thread (or really fast), then hookOnComplete won't flush the buffered data.

Related #501.

How Has This Been Tested?

Added a unit test to confirm behavior.

Breaking Changes

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

This branch has not been deployed

No deployments
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.

1 participant