fix(everything): drop a disconnected session from the subscriptions map - #4798
Open
voidstackloop wants to merge 1 commit into
Open
voidstackloop wants to merge 1 commit into
voidstackloop wants to merge 1 commit into
Conversation
`subscriptions` (a module-level `Map<uri, Set<sessionId>>` in resources/subscriptions.ts) adds a session id on `resources/subscribe` and removes it only on an explicit `resources/unsubscribe`. Nothing removed it when the session itself ended: `cleanup(sessionId)` (server/index.ts) already stops simulated logging and resource-update timers and cleans up the task store, but never touched `subscriptions`. A client that subscribes and disconnects without unsubscribing left its session id in every URI's Set for the life of the process. Added `removeSubscriber(sessionId)`, which deletes the session from every URI's Set and drops any URI entry left with no subscribers, and called it from `cleanup()` alongside the existing timer teardown. Added tests: a session removed via `removeSubscriber` gets no further simulated update notification, another subscriber to the same URI is unaffected, and calling it for a session with no subscriptions is a no-op. Full test suite (26 tests) and `tsc --noEmit` pass. Closes modelcontextprotocol#4710 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
subscriptions(a module-levelMap<uri, Set<sessionId>>in resources/subscriptions.ts) adds a session id onresources/subscribeand removes it only on an explicitresources/unsubscribe. Nothing removed it when the session itself ended:cleanup(sessionId)(server/index.ts) already stops simulated logging and resource-update timers and cleans up the task store, but never touchedsubscriptions.A client that subscribes and disconnects without unsubscribing left its session id in every URI's Set for the life of the process.
Added
removeSubscriber(sessionId), which deletes the session from every URI's Set and drops any URI entry left with no subscribers, and called it fromcleanup()alongside the existing timer teardown.Added tests: a session removed via
removeSubscribergets no further simulated update notification, another subscriber to the same URI is unaffected, and calling it for a session with no subscriptions is a no-op. Full test suite (26 tests) andtsc --noEmitpass.Closes #4710
Description
Publishing Your Server
Note: We are no longer accepting PRs to add servers to the README. Instead, please publish your server to the MCP Server Registry to make it discoverable to the MCP ecosystem.
To publish your server, follow the quickstart guide. You can browse published servers at https://registry.modelcontextprotocol.io/.
Server Details
Motivation and Context
How Has This Been Tested?
Breaking Changes
Types of changes
Checklist
Additional context