Skip to content

fix: close per-request server and transport in example-apps handler#42

Merged
ochafik merged 1 commit intomainfrom
fix/example-apps-cleanup
Apr 23, 2026
Merged

fix: close per-request server and transport in example-apps handler#42
ochafik merged 1 commit intomainfrom
fix/example-apps-cleanup

Conversation

@ochafik
Copy link
Copy Markdown
Contributor

@ochafik ochafik commented Apr 23, 2026

Summary

  • The stateless /:slug/mcp handler in src/modules/example-apps/index.ts creates a fresh McpServer + StreamableHTTPServerTransport on every request but never closes either, so they accumulate until GC pressure stalls the process under sustained load.
  • Register res.on('close', ...) to close both. Using 'close' (rather than 'finish') ensures cleanup also runs when the client aborts mid-SSE-stream.

Follow-up

  • src/modules/mcp/handlers/shttp.ts uses res.on('finish', ...) for its cleanup, which does not fire on client abort. May warrant the same 'close' treatment in a separate PR.

Test plan

  • npm run build
  • npm run lint
  • npm test (79/79)

The stateless /:slug/mcp handler creates a fresh McpServer and
StreamableHTTPServerTransport on every request but never closed them,
leaking memory under load. Register a 'close' listener (fires on both
normal completion and client abort mid-SSE) to release them.
@ochafik ochafik requested a review from pja-ant April 23, 2026 13:47
@ochafik ochafik merged commit 219bba3 into main Apr 23, 2026
4 checks 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.

2 participants