Skip to content

everything: remove disconnected sessions from resource subscriptions - #4711

Closed
vishalhabib99 wants to merge 1 commit into
modelcontextprotocol:mainfrom
vishalhabib99:fix/everything-subscription-cleanup
Closed

everything: remove disconnected sessions from resource subscriptions#4711
vishalhabib99 wants to merge 1 commit into
modelcontextprotocol:mainfrom
vishalhabib99:fix/everything-subscription-cleanup

Conversation

@vishalhabib99

Copy link
Copy Markdown

Fixes #4710.

subscriptions (Map<uri, Set<sessionId>> in src/everything/resources/subscriptions.ts) only ever had entries removed via an explicit resources/unsubscribe call. A session that disconnects without unsubscribing stayed in every Set it had joined for the life of the process — cleanup(sessionId) stops the logging/update intervals and task-store timers but never touched subscriptions.

Fix: add removeSubscriber(sessionId), which iterates the map, deletes the session from each Set, and drops any URI entry left with no subscribers. Call it from cleanup() alongside the existing calls, matching the pattern the reporter suggested in the issue.

Verified:

  • tsc --noEmit — clean
  • vitest run __tests__/resources.test.ts __tests__/server.test.ts — 29/29 passing
  • prettier --check — passes

Impact is limited to the reference everything server, but per the issue, it's the example people copy, so worth fixing correctly.

subscriptions (Map<uri, Set<sessionId>>) only ever had entries removed
via an explicit resources/unsubscribe call. A session that disconnects
without unsubscribing stayed in every Set it had joined for the life
of the process, since cleanup(sessionId) stopped logging/update
intervals and task-store timers but never touched subscriptions.

Add removeSubscriber(sessionId), which drops the session from every
URI's subscriber set and removes any URI entry left with no
subscribers, and call it from cleanup().

Fixes #4710
@vishalhabib99 vishalhabib99 closed this by deleting the head repository Aug 29, 2026
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