mcp: drain SSE messages when closing - #1192
Open
jstar0 wants to merge 1 commit into
Open
Conversation
jstar0
force-pushed
the
fix/1191-sse-close-drain
branch
from
September 12, 2026 12:33
44aeebb to
fd3a248
Compare
Contributor
Author
|
Rebased the single commit onto current |
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.
mcp: drain SSE messages when closing
SSEServerTransport.Closepreviously closed the session signal without draining buffered client messages. BecauseReadandServeHTTPselect between the message queue and the closed signal, a closed session could deliver stale messages or acknowledge a POST with202 Acceptedeven though the message would never be processed.This change drains buffered incoming messages when the server connection closes and checks the closed state around queue operations, so close races return
io.EOFor400 session closed. It adds regression tests for stale post-close reads and POST responses after close.Tests:
go test -race ./mcp -run '^(TestSSEServerConnCloseDrainsIncoming|TestSSEServerTransportServeHTTPAfterClose)$' -count=50— passed.go test ./...— passed on the rebased head.go vet ./...— passed.gofmt -d mcp/sse.go mcp/sse_test.go— no changes reported.Hosted checks for rebased head
fd3a248297cd62389764587e2949a3cb988c6611passed, including Test on Go 1.25 and 1.26, race-test, lint, client and server conformance, Analyze, and CodeQL.Fixes #1191