Skip to content

fix(mcp): exit cleanly on SIGTERM/SIGINT/stdin-end in MCP server#475

Open
JLMA-Agentic-Ai wants to merge 1 commit into
ruvnet:mainfrom
JLMA-Agentic-Ai:fix/sigterm-leak-mcp-server
Open

fix(mcp): exit cleanly on SIGTERM/SIGINT/stdin-end in MCP server#475
JLMA-Agentic-Ai wants to merge 1 commit into
ruvnet:mainfrom
JLMA-Agentic-Ai:fix/sigterm-leak-mcp-server

Conversation

@JLMA-Agentic-Ai
Copy link
Copy Markdown
Contributor

bin/mcp-server.js had no termination signal handlers. When the parent process is killed with SIGKILL or the connection drops without closing stdin gracefully, the MCP server continues running and is reparented to init (PPID=1), where it accumulates indefinitely and consumes RSS for the lifetime of the user session.

Add SIGINT, SIGTERM, and stdin 'end' handlers in main() that call process.exit(0).

Adds a regression test (test/sigterm-cleanup.js) that spawns the MCP server, sends each signal, and asserts a clean exit within 5 seconds. Wires the new test into the npm test script.

bin/mcp-server.js had no termination signal handlers. When the parent
process is killed with SIGKILL or the connection drops without closing
stdin gracefully, the MCP server continues running and is reparented
to init (PPID=1), where it accumulates indefinitely and consumes RSS
for the lifetime of the user session.

Add SIGINT, SIGTERM, and stdin 'end' handlers in main() that call
process.exit(0).

Adds a regression test (test/sigterm-cleanup.js) that spawns the MCP
server, sends each signal, and asserts a clean exit within 5 seconds.
Wires the new test into the npm test script.
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.

1 participant