Skip to content

TCP connections remain in CLOSE_WAIT state after client disconnection in SSE mode #378

Description

@hty690

Bug description
When clients terminate SSE connections with the Java MCP server, the underlying TCP connections remain in CLOSE_WAIT state, while the client side stays in FIN_WAIT_2. This can lead to resource leaks, especially in scenarios where clients cannot properly send RST signals (e.g., when using customized user-space network stacks).

Image

Environment
java version: 17
sdk version: 0.10.0
spring-ai.version: 1.0.0

Steps to reproduce

  1. setup a plain spring-ai mcp server, listen on localhost:8888/sse
  2. use inspector to call 127.0.0.1:8888/sse
  3. use inspector to list tool/call tools/...
  4. disconnect the connection and use netstat -anp|grep 8888

Expected behavior
All TCP connections should be closed properly.

Activity

  1. gemo12123 commented on Jul 10, 2025

    @gemo12123

    Perhaps you can try manually executing McpServerTransportProvider#notifyClients(McpSchema.METHOD_PING, null) on a scheduled basis.

  2. bigshi commented on Aug 4, 2025

    @bigshi

    I've encountered a similar issue, but in my case, it occurs when Nginx forwards requests to the MCP server. However, when testing disconnections using MCP Inspector v0.16.2, I couldn't reproduce the persistent CLOSE_WAIT state. Moreover, the ports in CLOSE_WAIT state still had one byte of unread data. I'm not sure where exactly the problem lies.

    My solution was to limit the timeout duration for SSE connections. By default, it was set to 0. We locally overrode the WebMvcSseServerTransportProvider and modified Duration.ZERO to 60 in the handleSseConnection method.

    However, this approach alters the fundamental nature of SSE long connections. So now, I'm trying the PING method mentioned above to see if it can resolve the issue.

    Image Image
  3. chemicL commented on Feb 19, 2026

    @chemicL
    Member

    This issue was opened prior to #430. Perhaps this has resolved the problem? Thanks in advance for re-assessing.

  4. added
    waiting for userWaiting for user feedback or more details
    bugSomething isn't working
    on Feb 19, 2026
  5. added theissue type on Feb 19, 2026
  6. Kehrlann commented on Jun 25, 2026

    @Kehrlann
    Contributor

    Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions