Skip to content

fix(everything): drop disconnected session from subscriptions map - #4718

Open
AbhiPra24 wants to merge 1 commit into
modelcontextprotocol:mainfrom
AbhiPra24:fix/everything-session-cleanup
Open

fix(everything): drop disconnected session from subscriptions map#4718
AbhiPra24 wants to merge 1 commit into
modelcontextprotocol:mainfrom
AbhiPra24:fix/everything-session-cleanup

Conversation

@AbhiPra24

Copy link
Copy Markdown
Contributor

Description

Fixes #4710

When a client session closes or disconnects, its session ID remained in the subscriptions map indefinitely. This patch introduces cleanupSubscriptions(sessionId) to remove the disconnected session from tracked URI subscriptions (and prune empty URIs from the map) and invokes it during server cleanup (cleanup(sessionId)). Also cleans up empty subscriber sets on explicit unsubscribe requests.

Changes

  • In src/everything/resources/subscriptions.ts: Added cleanupSubscriptions to remove all subscriptions for a session ID and delete empty URI entries; deleted empty URI sets in UnsubscribeRequestSchema handler; exported getSubscriptions for inspection/testing.
  • In src/everything/server/index.ts: Added cleanupSubscriptions(sessionId) to cleanup callback returned by createServer.
  • Added unit tests in src/everything/__tests__/resources.test.ts and src/everything/__tests__/server.test.ts to verify session subscription cleanup on disconnect.

Verification

  • npm --workspace=@modelcontextprotocol/server-everything test passed (108 tests passing).
  • npm run build passed.

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.

everything: subscriptions map never drops a disconnected session

1 participant