Skip to content

Official Codebase of 3DCodeVerse

Python

browser daemon: work in progress is not a leak

gaoypeng89bd923d579b
diff --git a/harness/runtime_js/browser_daemon.cjs b/harness/runtime_js/browser_daemon.cjs
index 2932119a..4b4ef7c7 100644
--- a/harness/runtime_js/browser_daemon.cjs
+++ b/harness/runtime_js/browser_daemon.cjs
@@ -85,7 +85,13 @@ async function main() {
}
const cur = (() => { try { return JSON.parse(fs.readFileSync(epPath, 'utf8')); } catch (_e) { return null; } })();
if (!cur || cur.ws !== record.ws) return bail(0); // superseded by another daemon
- try { // reap pages leaked by killed clients (never the initial about:blank)
+ const idle = Date.now() - st.mtimeMs;
+ // Reap leaked pages only when NOBODY is working: clients tick the heartbeat every
+ // 30 s while connected, so a fresh one means an old page belongs to live work. It
+ // used to tick on connect/release only, and a 16-minute scene probe had its page
+ // closed under it — 'Protocol error: Target closed'.
+ try {
+ if (idle < IDLE_REAP_MS) return;
const open = await browser.pages();
const now = Date.now();
const live = new Set(open);
@@ -95,7 +101,6 @@ async function main() {
else if (now - at > PAGE_TTL_MS) { firstSeen.delete(p); await p.close().catch(() => {}); }
}
} catch (_e) { /* browser mid-shutdown; the checks below handle it */ }
- const idle = Date.now() - st.mtimeMs;
if (idle < IDLE_REAP_MS) return;
let pages = 2;
try {
diff --git a/harness/runtime_js/gpu_launch.cjs b/harness/runtime_js/gpu_launch.cjs
index 0f472481..6ef29a7e 100644
--- a/harness/runtime_js/gpu_launch.cjs
+++ b/harness/runtime_js/gpu_launch.cjs
@@ -187,12 +187,22 @@ async function connectShared(puppeteer, backend) {
return null;
}
heartbeat(backend);
+ // Keep the heartbeat fresh WHILE the client works: it used to tick only on
+ // connect and release, so a scene probe holding one page for 16 minutes looked
+ // idle to the daemon, which closed its page (page TTL) or the whole browser
+ // (HARD_REAP_MS) out from under it — 'Protocol error: Target closed'.
+ const beat = setInterval(() => heartbeat(backend), 30_000);
+ if (beat.unref) beat.unref();
return {
browser,
gpu: !!info.gpu,
renderer: String(info.renderer || ''),
shared: true,
- release: async () => { heartbeat(backend); try { await browser.disconnect(); } catch (_e) { /* already gone */ } },
+ release: async () => {
+ clearInterval(beat);
+ heartbeat(backend);
+ try { await browser.disconnect(); } catch (_e) { /* already gone */ }
+ },
};
} catch (_e) {
// poisoned: the advertised browser is gone/unresponsive — forget it