Skip to content

[codex] fix MCP streamable HTTP close flake#3200

Merged
hengyunabc merged 1 commit into
masterfrom
codex/mcp-http-close-flake
May 25, 2026
Merged

[codex] fix MCP streamable HTTP close flake#3200
hengyunabc merged 1 commit into
masterfrom
codex/mcp-http-close-flake

Conversation

@hengyunabc
Copy link
Copy Markdown
Collaborator

Summary

Fix a flaky MCP Streamable HTTP integration test failure where HttpURLConnection can reuse a socket that the server has already closed after initialize, causing java.net.SocketException: Unexpected end of file from server in ArthasMcpToolsIT on 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 advertise Connection: 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

  • Add Connection: close to MCP server responses that close the channel after non-SSE responses.
  • Add Connection: close to top-level MCP error responses.
  • Harden handwritten MCP HttpURLConnection test clients to request close, disconnect after each response, and retry notifications/initialized on transient IOException.

Validation

  • git diff --check
  • mvn -V -ntp -pl arthas-mcp-integration-test -am -Dtest=com.taobao.arthas.mcp.it.ArthasMcpToolsIT -Dsurefire.failIfNoSpecifiedTests=false verify
  • mvn -V -ntp -pl arthas-mcp-integration-test verify

@hengyunabc hengyunabc requested a review from Copilot May 25, 2026 16:50
@hengyunabc hengyunabc marked this pull request as ready for review May 25, 2026 16:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: close to MCP server HTTP responses that immediately close the Netty channel (including error responses).
  • Update handwritten HttpURLConnection test clients to request Connection: close and always disconnect() after each request.
  • Add a small retry/backoff for notifications/initialized to tolerate transient IOException during 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.

@hengyunabc hengyunabc merged commit 620dec4 into master May 25, 2026
17 checks passed
@hengyunabc hengyunabc deleted the codex/mcp-http-close-flake branch May 25, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants