Skip to content

fix(stdio): session cleanup on exit#302

Open
oshliaer wants to merge 2 commits intohangwin:masterfrom
oshliaer:fix/stdio-session-cleanup
Open

fix(stdio): session cleanup on exit#302
oshliaer wants to merge 2 commits intohangwin:masterfrom
oshliaer:fix/stdio-session-cleanup

Conversation

@oshliaer
Copy link

@oshliaer oshliaer commented Feb 22, 2026

Encountered an issue when switching between MCP clients in stdio mode. After several connect/disconnect cycles, all sessions became occupied and new clients could not connect.

Changes:

  • Save session ID on connect
  • Send explicit DELETE request on process exit (cleanup function)
  • Add stdin.on(end/close) handlers to trigger cleanup
  • Add parent PID watchdog as backup mechanism

This ensures sessions are properly released on the server when stdio client terminates.

Signed-off-by: Alexander Ivanov <oshli.a.er@gmail.com>
Copilot AI review requested due to automatic review settings February 22, 2026 18:51
Copy link

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

This PR addresses MCP Streamable HTTP session cleanup for the stdio MCP server by tracking the client transport session ID and terminating it when the stdio process exits.

Changes:

  • Persist the Streamable HTTP client sessionId after connecting so it can be cleaned up later.
  • Add an async shutdown routine that issues an HTTP DELETE /mcp with Mcp-Session-Id before closing the MCP client/server and exiting.
  • Add exit detection via stdin end/close handlers plus a parent-PID watchdog timer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@oshliaer oshliaer changed the title fix: stdio session Fix: STDIO session cleanup on exit Feb 22, 2026
- Remove redundant non-null assertion (sessionId!)
- Add isCleaningUp flag to prevent concurrent cleanup calls
- Add AbortController with 3s timeout for DELETE request
- Check ESRCH error code in parent PID watchdog

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@oshliaer oshliaer changed the title Fix: STDIO session cleanup on exit fix(stdio): session cleanup on exit Feb 22, 2026
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