fix: kill stale MCP processes on reconnect to same endpoint#1761
Draft
yuvrajangadsingh wants to merge 1 commit intoChromeDevTools:mainfrom
Draft
fix: kill stale MCP processes on reconnect to same endpoint#1761yuvrajangadsingh wants to merge 1 commit intoChromeDevTools:mainfrom
yuvrajangadsingh wants to merge 1 commit intoChromeDevTools:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When MCP clients reconnect (e.g. running
/mcpin Claude Code), each reconnect spawns a newchrome-devtools-mcpprocess without killing the previous one. Multiple CDP clients on the same debug port causeNetwork.enable timed outerrors because sessions conflict.Reproducing is easy: run
/mcpthree times in a row and checklsof -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:
openSyncwithwxflag)process.exit())Lock files are keyed by normalized endpoint URL (not just port) so different hosts on the same port don't collide. Both
--browserUrland--wsEndpointconnections are covered.Changes
src/browser.ts:acquireEndpointLock()andreleaseEndpointLock()functionssrc/bin/chrome-devtools-mcp-main.ts: early lock acquisition on startup, cleanup on exitTested
Verified locally on macOS with Arc browser (port 9222):
Fixes #1763
Related: #1156, #657