[codex] fix MCP streamable HTTP close flake#3200
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a flaky MCP streamable HTTP integration-test failure caused by the server closing HTTP/1.1 connections without advertising Connection: close, allowing HttpURLConnection to reuse a socket that the server is already closing.
Changes:
- Add
Connection: closeto MCP server HTTP responses that immediately close the Netty channel (including error responses). - Update handwritten
HttpURLConnectiontest clients to requestConnection: closeand alwaysdisconnect()after each request. - Add a small retry/backoff for
notifications/initializedto tolerate transientIOExceptionduring connection teardown.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/protocol/server/handler/McpStreamableHttpRequestHandler.java | Adds Connection: close to non-SSE responses and error responses that close the channel immediately. |
| arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/protocol/server/handler/McpHttpRequestHandler.java | Adds Connection: close to top-level HTTP error responses that close the channel. |
| arthas-mcp-integration-test/src/test/java/com/taobao/arthas/mcp/it/task/ArthasMcpTaskTestSupport.java | Hardens integration-test HTTP client behavior (request close, disconnect in finally, retry initialized notification). |
| arthas-mcp-integration-test/src/test/java/com/taobao/arthas/mcp/it/ArthasMcpToolsIT.java | Applies the same HTTP client hardening to the ArthasMcpToolsIT test client. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Fix a flaky MCP Streamable HTTP integration test failure where
HttpURLConnectioncan reuse a socket that the server has already closed afterinitialize, causingjava.net.SocketException: Unexpected end of file from serverinArthasMcpToolsITon CI.Root cause
The streamable HTTP server writes several ordinary JSON/empty HTTP responses and immediately closes the Netty channel with
ChannelFutureListener.CLOSE, but those responses did not advertiseConnection: close. Under HTTP/1.1, the client can treat the socket as reusable and send the next MCP POST (notifications/initialized) on a closing connection.Changes
Connection: closeto MCP server responses that close the channel after non-SSE responses.Connection: closeto top-level MCP error responses.HttpURLConnectiontest clients to request close, disconnect after each response, and retrynotifications/initializedon transientIOException.Validation
git diff --checkmvn -V -ntp -pl arthas-mcp-integration-test -am -Dtest=com.taobao.arthas.mcp.it.ArthasMcpToolsIT -Dsurefire.failIfNoSpecifiedTests=false verifymvn -V -ntp -pl arthas-mcp-integration-test verify