Remove unused per-session channels from StreamableSession#4076
Merged
ChrisJBurns merged 14 commits intomainfrom Mar 11, 2026
Merged
Remove unused per-session channels from StreamableSession#4076ChrisJBurns merged 14 commits intomainfrom
ChrisJBurns merged 14 commits intomainfrom
Conversation
StreamableSession eagerly allocated two buffered channels (100 slots each, ~3 KB) per session, but neither the streamable HTTP proxy nor the vMCP server ever use per-session channels — they route through global proxy channels instead. Under high session churn (60k+ create/delete cycles), these unused allocations contributed to monotonic memory growth leading to OOMKill. Channels are now nil by default and lazily allocated via sync.Once on first SendMessage/SendResponse call. Disconnect() guards against nil channels. No behavioral change for callers that use the channels. Relates to #4062 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4076 +/- ##
==========================================
+ Coverage 68.65% 68.72% +0.07%
==========================================
Files 454 454
Lines 46051 46027 -24
==========================================
+ Hits 31616 31634 +18
+ Misses 11994 11953 -41
+ Partials 2441 2440 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Channels are nil after construction - SendMessage/SendResponse allocate both channels on first call - Disconnect is safe with nil channels - Send after Disconnect returns error - GetData returns zeros when channels are nil Signed-off-by: Chris Burns <29541485+ChrisJBurns@users.noreply.github.com>
jerm-dro
previously approved these changes
Mar 10, 2026
Contributor
jerm-dro
left a comment
There was a problem hiding this comment.
I'm surprised these weren't garbage collected. I wonder if this object is still being leaked somehow? Regardless, this change is definitely an improvement, so LGTM.
…cklok/toolhive into fix/streamable-session-lazy-channels
…treamableSession Neither the streamable HTTP proxy nor the vMCP server use per-session channels — both route messages through global proxy-level channels. Remove the dead fields and methods entirely rather than lazy-initializing them, eliminating ~4 KB of wasted memory per session. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The remaining tests only verified struct construction and a boolean flag toggle — no meaningful behavior worth testing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jerm-dro
approved these changes
Mar 11, 2026
amirejaz
approved these changes
Mar 11, 2026
Collaborator
|
I think you can rebase |
…cklok/toolhive into fix/streamable-session-lazy-channels
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
MessageCh,ResponseCh) — both route messages through global proxy-level channels instead. EachStreamableSessionwas eagerly allocating two buffered channels (100 slots each, ~4 KB combined) that were never read from or written to.MessageCh,ResponseCh), methods (SendMessage,SendResponse,initChannels), and supporting infrastructure (chOnce,streamableChannelBufferconstant) entirely. This eliminates ~4 KB of wasted memory per session under churn, reducing peak heap pressure that contributed to OOMKill at 128Mi.Ref #4062
Type of change
Test plan
task test)task lint-fix)Verified no code outside the session package references
StreamableSession.MessageCh,ResponseCh,SendMessage, orSendResponse. TheVMCPSessiontype embedsStreamableSessionand also never uses the removed fields.Does this introduce a user-facing change?
No.
Special notes for reviewers
sync.Once. Since nothing ever callsSendMessage/SendResponse, full removal is simpler and more effective.MessageChandSendMessageare unaffected — those are actively used by the SSE proxy.Generated with Claude Code