Skip to content

fix: kill stale MCP processes on reconnect to same endpoint#1761

Draft
yuvrajangadsingh wants to merge 1 commit intoChromeDevTools:mainfrom
yuvrajangadsingh:fix/kill-stale-connections
Draft

fix: kill stale MCP processes on reconnect to same endpoint#1761
yuvrajangadsingh wants to merge 1 commit intoChromeDevTools:mainfrom
yuvrajangadsingh:fix/kill-stale-connections

Conversation

@yuvrajangadsingh
Copy link
Copy Markdown

@yuvrajangadsingh yuvrajangadsingh commented Mar 30, 2026

Problem

When MCP clients reconnect (e.g. running /mcp in Claude Code), each reconnect spawns a new chrome-devtools-mcp process without killing the previous one. Multiple CDP clients on the same debug port cause Network.enable timed out errors because sessions conflict.

Reproducing is easy: run /mcp three times in a row and check lsof -i :9222. You'll see 3+ node processes all connected to the same debug port.

Fix

Adds endpoint-based PID lock files. On startup, the server:

  1. Checks if another instance is already connected to the same endpoint
  2. Sends SIGTERM (with SIGKILL fallback after 1s)
  3. Waits for the old process to actually exit
  4. Acquires the lock with its own PID (atomic via openSync with wx flag)
  5. Releases the lock on exit (SIGINT/SIGTERM/exit handlers call process.exit())

Lock files are keyed by normalized endpoint URL (not just port) so different hosts on the same port don't collide. Both --browserUrl and --wsEndpoint connections are covered.

Changes

  • src/browser.ts: acquireEndpointLock() and releaseEndpointLock() functions
  • src/bin/chrome-devtools-mcp-main.ts: early lock acquisition on startup, cleanup on exit

Tested

Verified locally on macOS with Arc browser (port 9222):

  • Instance 1 acquires lock, Instance 2 kills Instance 1 and takes over
  • Lock file correctly transitions between PIDs
  • Old process actually dies (SIGTERM + SIGKILL fallback)
  • Lock released on clean exit

Fixes #1763
Related: #1156, #657

When MCP clients reconnect (e.g. via /mcp in Claude Code), each
reconnect spawns a new chrome-devtools-mcp process. Multiple CDP
clients on the same debug port cause 'Network.enable timed out'
errors because sessions conflict.

This adds endpoint-based PID lock files. On startup, the server
checks if another instance is already connected to the same
endpoint, sends SIGTERM (with SIGKILL fallback after 1s), waits
for it to die, then acquires the lock. On exit, the lock is
released.

Lock files are keyed by normalized endpoint URL (not just port)
so different hosts on the same port don't collide. Both browserUrl
and wsEndpoint connections are covered.
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.

multiple MCP processes on same debug port cause Network.enable timeout

1 participant