From 693b5e86268421b5c6e3400d988efdcc25f2e34e Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Sun, 26 Jul 2026 00:33:44 +0530 Subject: fix: kill leaked Chrome processes on profile seed failure When a profile is pinned and ProcessSingleton fails to delegate, the spawned Chrome process starts a full second browser instance. The sentinel never appeared, but the spawned process was never killed (detached + unref'd + reference discarded), accumulating zombie browsers that consume RAM. Three changes: - Store child process ref and expose kill() on ProfileWindowHandle. Call kill() when the sentinel doesn't appear within the timeout. - Only clear profileContextId when the browser UUID changes (Chrome mints a fresh UUID on every launch), avoiding unnecessary re-spawns. - Don't clear profileContextId in setProfilePin when the pin hasn't changed, preventing gratuitous re-spawns on session_start. --- src/profile/bind.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/profile/bind.ts') diff --git a/src/profile/bind.ts b/src/profile/bind.ts index aeb59d3..10b38a3 100644 --- a/src/profile/bind.ts +++ b/src/profile/bind.ts @@ -93,7 +93,7 @@ export const seedProfileWindow = async ( return err(cdpError("discovery_failed", `${launched.error} — ${manualFallbackHint(pin)}`)); } - const { sentinelUrl, cleanup } = launched.data; + const { sentinelUrl, cleanup, kill } = launched.data; const deadline = Date.now() + SEED_DEADLINE_MS; let seed: PageTarget | undefined; while (Date.now() < deadline && !seed) { @@ -102,6 +102,7 @@ export const seedProfileWindow = async ( } if (!seed) { + kill(); await cleanup(); return err(cdpError( "timeout", -- cgit v1.2.3