fix(mcp): add TTL-based session cleanup to prevent memory leak#194
Open
Satvik77777 wants to merge 3 commits into
Open
fix(mcp): add TTL-based session cleanup to prevent memory leak#194Satvik77777 wants to merge 3 commits into
Satvik77777 wants to merge 3 commits into
Conversation
added 3 commits
June 5, 2026 11:07
Resolves test coverage gap for the new MCP handler. - Extracted getServer() for testability. - Wrote tests for HTTP boundary error cases (400 responses). - Wrote internal tests using InMemoryTransport to verify getTemplate, getAgreement, and trigger-agreement tools directly without battling strict StreamableHTTPServerTransport payload requirements. - Fixed a bug where mcp-session-id was checked on incoming requests but not attached to the outgoing initialize response header. Signed-off-by: Satvik77777 <satvikaini02@gmail.com>
- locks in the session header bug fix against future regression - per review feedback from @JayDS22 Signed-off-by: Satvik77777 <satvikaini02@gmail.com>
- add sessionLastActivity map tracking last request timestamp per session - add setInterval cleanup every 5 minutes removing sessions idle for 30+ minutes - call .unref() on interval to prevent blocking process exit - update lastActivity on every incoming request for existing sessions - clean up sessionLastActivity on transport.onclose and SSE disconnect - add structured logging for session cleanup events - closes accordproject#193 Signed-off-by: Satvik77777 <satvikaini02@gmail.com>
Contributor
Author
|
Hi @niallroche @mttrbrts — this PR fixes a memory |
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.
Summary
The global transports map in mcp.ts had no cleanup
mechanism. Sessions were only removed when
transport.onclose fired correctly. Unclean client
disconnects (network drops, crashes, timeouts) left
transports in the map forever, causing unbounded
memory growth that crashes the server in production.
What this PR does
New cleanup mechanism
timestamp per session
idle for 30+ minutes
Activity tracking
for existing sessions
Cleanup on disconnect
Tests (3 new, 14 total passing)
References
Author Checklist