Skip to content

Conversation

phanikpemmaraju
Copy link

Motivation and Context

  • "closeGracefully()" could skip disposing open connections when onClose threw, leading to leaked resources during server outages or abrupt disconnects.
  • MCP session id is optional; when the server doesn’t return one, client flows that assumed a non-null id would throw "Session ID missing" prematurely.

How Has This Been Tested?

"Unit tests"

  • closeGracefully disposes connections when onClose throws.
  • Disposal exceptions are aggregated/suppressed as appropriate; error semantics preserved.

"Integration tests"

  • WebFlux/SSE: server crashes mid-session → closeGracefully() best-effort local teardown still runs (existing WebFluxSseCloseGracefullyIntegrationTests).

Breaking Changes

  • "None"

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

"What's changed"

  • Wrap onClose.apply(sessionId) in try/finally and always dispose openConnections in the finally block.
  • Add a null/absent session id guard before reconnect/close paths; treat missing id as “no remote teardown”, but still perform local cleanup.
  • Improved test coverage (unit + integration).

"Why"

  • Ensures robust cleanup even when the remote close fails or server is gone.
  • Prevents spurious “Session ID missing” errors when servers legitimately omit a session id.

@phanikpemmaraju
Copy link
Author

looking for reviewers to review the same.

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