Skip to content

Server-side StreamableHTTPServerTransport.close() does not fully clean up, causing nodemon hang on shutdown #783

@Liron-Wassa

Description

@Liron-Wassa

Describe the bug
Calling transport.close() on the NodeJS server-side StreamableHTTPServerTransport does not fully close all active streaming connections or resources. As a result, the Node.js process does not exit cleanly, and nodemon hangs with the message:
[nodemon] still waiting for 1 sub-process to finish...

To Reproduce

  1. Steps to reproduce the behavior:
  2. Run an MCP server using StreamableHTTPServerTransport.
  3. Connect one or more streaming clients (e.g., MCP inspector).
  4. Handle shutdown signals (SIGINT, SIGTERM) by calling transport.close() and closing the HTTP server.
  5. Observe that despite calling transport.close(), the Node process remains alive and nodemon hangs waiting for the process to exit.

Expected behavior

  1. Calling transport.close() on StreamableHTTPServerTransport should:
  2. Immediately terminate all active streaming connections (SSE or HTTP streams).
  3. Clean up all timers, event listeners, and other resources.
  4. Fully free all handles so that the Node.js process can exit cleanly after shutdown.

Logs
If applicable, add logs to help explain your problem.
console.log('Active handles:', (process as any)._getActiveHandles());
shows lingering Socket and Server handles even after calling transport.close().

Also, nodemon logs:
[nodemon] still waiting for 1 sub-process to finish...

Additional context
This issue occurs specifically during shutdown triggered by process signals (SIGINT and SIGTERM). Despite closing the transport and HTTP server, active connections or internal resources remain open, preventing clean process exit. Improving transport.close() to fully clean resources on signal-triggered shutdown would greatly improve usability and developer experience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions