Repository navigation
fix(mcp): close the SSE connection when the legacy transport is dropped - #514
Merged
Merged
Conversation
LegacySseTransport kept its reader task as a JoinHandle. Dropping a JoinHandle only detaches the task, and the reader notices a dropped receiver only when it has an event to send. A server that just sends keep-alive comments therefore kept one task and one open connection per dropped transport for the life of the process. A connect that timed out waiting for the endpoint event left the same task behind. The handle now lives in SseReader, which aborts the task on drop. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Merged
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.
Problem
LegacySseTransportkept its reader task as aJoinHandle. Dropping aJoinHandleonly detaches the task. The reader notices a dropped receiver only when it has an event to send, and a keep-alive comment is not an event. So a server that only sends keep-alives kept one task and one open HTTP connection per dropped transport, for the life of the process. Aconnectthat timed out waiting for theendpointevent left the same task behind.Fix
The handle lives in
SseReader, whoseDropaborts the task. The response body and its connection go with the transport, on both the normal drop and the failed-connect path.Tests
dropping_the_legacy_transport_closes_its_sse_connectionanda_connect_that_never_gets_an_endpoint_closes_its_sse_connection: a raw TCP server sends keep-alives until a write fails. Both fail onmain(connection still open after 5 s) and pass here.sse_reader_stops_by_itself_when_nobody_receives: aborting early removed the only indirect coverage of the reader's own exit line, so it gets a direct test.Verification
cargo test -p whycodes-mcp: 79 + 10 passed. Clippy, fmt, budget scripts: green.-skip-expansions, aftercargo llvm-cov clean).http.rsmisses 6 lines here on bothmainand this branch, allwarn!field lines that this Windows host reports and CI does not. The fullscripts/coverage.shworkspace run was not done locally.docs/knowhow.mdhas the entry.🤖 Generated with Claude Code