Skip to content

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented Aug 26, 2025

  • Add hasRequestedDemand volatile boolean flag to AggregateSubscriber and BodilessResponseLineSubscriber
  • Modify hookOnSubscribe to request Long.MAX_VALUE only on first demand request
  • Guard event emission in hookOnComplete with hasRequestedDemand check
  • Prevents unnecessary data processing when no downstream demand exists
  • Improves backpressure handling and resource efficiency

This change implements proper demand-based request handling by tracking whether demand has been requested and only emitting data when there's actual downstream demand.

Motivation and Context

The previous implementation would always emit data in hookOnComplete() regardless of whether there was downstream demand for it. This could lead to:

  • Not Maintaining backpressure compliance
  • Unnecessary data processing and memory allocation
  • Potential resource waste when subscribers don't request data

Breaking Changes

No breaking changes. This is an internal implementation improvement that maintains the same public API while improving resource efficiency and backpressure handling.

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

This change improves the reactive streams compliance and resource efficiency without affecting the public API.

- Add hasRequestedDemand volatile boolean flag to AggregateSubscriber and BodilessResponseLineSubscriber
- Modify hookOnSubscribe to request Long.MAX_VALUE only on first demand request
- Guard event emission in hookOnComplete with hasRequestedDemand check
- Prevents unnecessary data processing when no downstream demand exists
- Improves backpressure handling and resource efficiency

Signed-off-by: Christian Tzolov <[email protected]>
@tzolov tzolov added this to the 0.12.0 milestone Aug 26, 2025
@tzolov tzolov merged commit 336f202 into modelcontextprotocol:main Aug 26, 2025
1 check passed
tzolov added a commit that referenced this pull request Aug 26, 2025
…516)

- Add hasRequestedDemand volatile boolean flag to AggregateSubscriber and BodilessResponseLineSubscriber
- Modify hookOnSubscribe to request Long.MAX_VALUE only on first demand request
- Guard event emission in hookOnComplete with hasRequestedDemand check
- Prevents unnecessary data processing when no downstream demand exists
- Improves backpressure handling and resource efficiency

Signed-off-by: Christian Tzolov <[email protected]>
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.

2 participants