Close WebMvcStreamableServerTransportProvider transports on disconnect - #6871
Open
lxq19991111 wants to merge 1 commit into
Open
Close WebMvcStreamableServerTransportProvider transports on disconnect#6871lxq19991111 wants to merge 1 commit into
WebMvcStreamableServerTransportProvider transports on disconnect#6871lxq19991111 wants to merge 1 commit into
Conversation
WebMvcStreamableServerTransportProvider transports on disconnect
lxq19991111
force-pushed
the
fix-streamable-transport-lifecycle
branch
from
August 28, 2026 01:33
2858e30 to
b10647a
Compare
Register SSE lifecycle cleanup so a client that disconnects without a clean DELETE no longer leaves the listening stream, replay stream, or streaming-response transport dangling. Route every lifecycle event through the same idempotent transport close() instead of a separate markClosed() flag, and route SSE write failures through the close path so a write failure closes only the current transport without removing the logical MCP session. Closes spring-projects#6860 Signed-off-by: lxq19991111 <15060002560@163.com>
lxq19991111
force-pushed
the
fix-streamable-transport-lifecycle
branch
from
August 31, 2026 15:20
b10647a to
e4325f5
Compare
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.
Fixes #6860
Makes the WebMVC Streamable HTTP SSE transport close when the SSE response completes, times out, or errors, and routes SSE write failures through the transport
close()path instead of only reporting the error to theSseBuilder.It mirrors modelcontextprotocol/java-sdk#1027: listening streams close on timeout/error as well as completion, replay and streaming responses close on lifecycle events, and every lifecycle event uses the same idempotent
close()(no separatemarkClosed()flag).Key design point: a write failure closes only the current HTTP/SSE transport and does NOT remove the logical MCP session. Removing the session on a request-specific write failure would break the next request carrying the same
mcp-session-idand Last-Event-ID replay, so session eviction is intentionally left to DELETE / keep-alive eviction.Testing
Rewrote both tests without reflection, using a package-private transport factory seam (the provider exposes a
RouterFunction, so the SDK-style servlet entry-point mocking is not applicable here):sseLifecycleCallbacksCloseStreamOnCompleteTimeoutAndErrorasserts all three lifecycle callbacks trigger the close callback.sseWriteFailureClosesOnlyCurrentTransportWithoutRemovingSessioninitializes a session over the router, triggers an SSE write failure, verifies the transport is completed, and then deletes the session with the same id, asserting 200 to prove the session was retained.mvn -pl mcp/transport/mcp-spring-webmvc -am \ -Dtest=WebMvcStreamableServerTransportProviderTests \ -Dsurefire.failIfNoSpecifiedTests=false testModule unit tests pass, and WebMcpStreamableAsyncServerTransportIT, WebMcpStreamableSyncServerTransportIT, and WebMvcStreamableIT pass.