[PR #7424] fix: force kill MCP server processes on dispose to prevent orphan processes #12395

Open
opened 2026-02-16 18:17:18 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7424

State: open
Merged: No


Relates to #3013, #7261

Summary

  • Track local MCP server transports to enable forceful process termination
  • Add forceKillProcess() helper for cross-platform process termination
  • Force kill remaining MCP processes on dispose after graceful close timeout
  • Check if process is alive before attempting force kill

Problem

The MCP SDK's client.close() uses AbortController.abort() which may not work reliably for:

  • Docker containers without --init flag
  • Hung or unresponsive processes
  • Processes that don't handle signals properly

Solution

Defensive fallback that only triggers if graceful close doesn't work:

  1. Try graceful client.close() with 2 second timeout
  2. Check if process is still alive
  3. Force kill only if still running

Testing

Added tests in test/mcp/process-cleanup.test.ts.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7424 **State:** open **Merged:** No --- Relates to #3013, #7261 ## Summary - Track local MCP server transports to enable forceful process termination - Add `forceKillProcess()` helper for cross-platform process termination - Force kill remaining MCP processes on dispose after graceful close timeout - Check if process is alive before attempting force kill ## Problem The MCP SDK's `client.close()` uses `AbortController.abort()` which may not work reliably for: - Docker containers without `--init` flag - Hung or unresponsive processes - Processes that don't handle signals properly ## Solution Defensive fallback that only triggers if graceful close doesn't work: 1. Try graceful `client.close()` with 2 second timeout 2. Check if process is still alive 3. Force kill only if still running ## Testing Added tests in `test/mcp/process-cleanup.test.ts`.
yindo added the pull-request label 2026-02-16 18:17:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12395