Skip to content

fix(browse): kill old server before restart to prevent orphaned chromium processes#296

Closed
eternalwaitt wants to merge 1 commit intogarrytan:mainfrom
eternalwaitt:fix/browse-orphaned-chromium-cleanup
Closed

fix(browse): kill old server before restart to prevent orphaned chromium processes#296
eternalwaitt wants to merge 1 commit intogarrytan:mainfrom
eternalwaitt:fix/browse-orphaned-chromium-cleanup

Conversation

@eternalwaitt
Copy link

Problem

When the browse server's health check fails or the connection drops (e.g. pages that crash during hydration or trigger hard navigations via window.location.href), ensureServer() and sendCommand() call startServer() without killing the previous server process first.

This leaves orphaned chrome-headless-shell renderer processes running at ~120% CPU each. After several reconnect cycles, dozens of zombie chromium processes accumulate and exhaust system resources — in my case, 7 processes at ~840% CPU total, which crashed my dev server.

Fix

Call killServer() on the stale PID before spawning a new server in both restart paths:

  • ensureServer() — when the health check fails
  • sendCommand() — when the connection is lost (ECONNREFUSED/ECONNRESET)

Testing

Simulated a frozen server via kill -STOP (health check timeout path):

  • Before fix: old chromium processes survive, new ones spawn → process count doubles each cycle
  • After fix: old server + its chromium children are killed before new server starts → process count stays constant

Fixes #294

…ium processes

When the health check fails or the server connection drops, `ensureServer()`
and `sendCommand()` would call `startServer()` without first killing the
previous server process. This left orphaned `chrome-headless-shell` renderer
processes running at ~120% CPU each.

After several reconnect cycles (e.g. pages that crash during hydration or
trigger hard navigations via `window.location.href`), dozens of zombie
chromium processes accumulate and exhaust system resources.

Fix: call `killServer()` on the stale PID before spawning a new server in
both the `ensureServer()` unhealthy path and the `sendCommand()` connection-
lost retry path.

Fixes garrytan#294
@garrytan
Copy link
Owner

Merged into #325 (wave 1: /cso launch + security hardening). Thank you for the contribution!

@garrytan garrytan closed this Mar 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.

browse: orphaned chrome-headless-shell processes leak CPU on CDP disconnect

3 participants