mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 23:43:35 +00:00
* 🧹 fix: Terminate Streamable HTTP MCP sessions on teardown to prevent server-side leaks The MCP client only called client.close() when discarding a Streamable HTTP connection, never the spec-mandated HTTP DELETE with the Mcp-Session-Id header. Stateful MCP servers (the SDK default) keep each session's transport, tasks, and buffers in memory with no TTL, so every idle eviction, reconnect, or restart leaked one server-side session. Add terminateStreamableSession() and call it before client.close() (which aborts the transport controller and would cancel the in-flight DELETE) on both teardown paths: disconnect() and the reconnect transport swap. It is bounded by a 5s timeout so teardown never blocks on a hung server, and swallows errors since terminateSession() already no-ops without a session id and tolerates a 405. * 🛡️ fix: Suppress reconnect on failed session DELETE; harden termination tests Address Codex review on #14252. - P2: terminateSession() invokes transport.onerror before rejecting on any non-405 failure (session already expired, network error, or client.close() aborting after the timeout). Our handler turned that into connectionChange('error') -> handleReconnection(), reopening the connection mid-teardown and re-leaking the session. Detach transport.onerror before terminating; the transport is discarded immediately after, so it is safe. Add a regression test that fails before this change. - P3: bind test HTTP servers directly to an ephemeral port (listen(0) + read address) instead of probing a port and rebinding, removing a bind/listen race under parallel CI. - P3: null-init the server handles and guard close() so a startup failure surfaces the real error instead of a masking TypeError. |
||
|---|---|---|
| .. | ||
| src | ||
| types | ||
| .gitignore | ||
| babel.config.cjs | ||
| jest.config.mjs | ||
| jest.setup.cjs | ||
| package.json | ||
| tsconfig-paths-bootstrap.mjs | ||
| tsconfig.build.json | ||
| tsconfig.json | ||
| tsconfig.spec.json | ||
| tsdown.config.mjs | ||