fix: close servlet streamable HTTP transports on async lifecycle events#1039
Closed
neerajbhatt wants to merge 1 commit into
Closed
Conversation
Register AsyncListener on all three async paths in HttpServletStreamableServerTransportProvider (GET replay, GET listening stream, POST streaming response) so that transports are properly closed when clients disconnect, the async context times out, or an error occurs. Without these listeners, server sockets were left in CLOSE-WAIT state, exhausting Tomcat thread/connection resources. Also route SSE write failures in sendMessage() through the transport close() method instead of directly removing the session from the registry. Transport-level failures should not evict the logical MCP session, which may still be resumable via a new connection. Fixes modelcontextprotocol#1021
Author
|
Closing in favor of #1027 which addresses the same issue. |
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.
Summary
Fixes #1021 — server sockets left in CLOSE-WAIT state when clients disconnect from SSE streams.
AsyncListeneron all three async paths inHttpServletStreamableServerTransportProvider(GET replay, GET listening stream, POST streaming response) so transports are properly closed on client disconnect, async timeout, or errorregisterAsyncLifecyclehelper to consolidate the listener boilerplate across all three pathssendMessage()throughtransport.close()instead of directly removing the session from the session registry — transport failures should not evict the logical MCP session, which may be resumable via a new connectionTest plan
HttpServletStreamableAsyncServerTests— 35 tests passHttpServletStreamableIntegrationTests— 36 tests passHttpServletStreamableSyncServerTests— 34 tests pass