csharp-sdk/tests/ModelContextProtocol.Tests/Transport
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Joel Forsyth 4d011995d1 Release SSE response stream reference when GET request ends
StreamableHttpServerTransport held a reference to the Kestrel SSE
response stream via _httpSseWriter for the entire session lifetime.
Since the transport is only disposed when the session itself is disposed
(via explicit DELETE or idle timeout), clients that disconnect without
sending DELETE — which is typical for long-lived SSE connections — left
the response stream pinned for the remainder of the idle timeout window.

Because the Kestrel HTTP connection (and its associated memory pool
buffers, Pipe readers/writers, socket send/receive buffers) is only
collectible once all references to the response stream are released,
this pinned ~20MiB of unmanaged memory per disconnected session until
cleanup. Under steady connect/disconnect churn (e.g., IDE availability
probes) this accumulated into sustained memory growth that eventually
OOMKilled the container.

Fix: release _httpSseWriter from within HandleGetRequestAsync's finally
block so the reference is dropped as soon as the GET request exits, not
just when the session is disposed. SendMessageAsync handles the
now-nullable field via the existing _getHttpResponseCompleted gate, and
any server-to-client messages sent after disconnect are still captured
by the event store writer for replay via Last-Event-ID.

Add a unit test that verifies _httpSseWriter is null once
HandleGetRequestAsync returns.

Relates to #766.
2026-06-05 16:52:49 -07:00
..
HttpClientTransportAutoDetectTests.cs Restructure IMcpEndpoint, IMcpClient, and IMcpServer (#723) 2025-09-16 10:22:10 -07:00
HttpClientTransportTests.cs Fix off-by-one error in reconnection attempts (#1356) 2026-02-23 11:38:47 -05:00
SseResponseStreamTransportTests.cs Enable netfx testing. (#588) 2025-07-08 18:50:37 +03:00
StdioClientTransportTests.cs Stop logging stdio transport environment variables (#1538) 2026-06-03 01:58:52 -07:00
StdioServerTransportTests.cs Fix process crash when testing Stderr (#1449) 2026-04-06 11:29:00 -07:00
StreamableHttpServerTransportTests.cs Release SSE response stream reference when GET request ends 2026-06-05 16:52:49 -07:00