← Commit history

Make the orphan-renderer reap NON-BLOCKING: the v1.9.78 reap ran a synchronous 8s PowerShell CIM query on the close path, freezing the event loop and making the bridge unresponsive to AD's health check (self-inflicted restart). Fire-and-forget async instead

John Lauer ·702c0b5f3b ·3mo ago ·parent 9a4096b
4 files changed +25−16
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "1.9.80",-  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.80/adom-bridge-puppeteer-v1.9.80.zip",-  "sha256": "5d238c259d4de458970c697034eeb38a308627f18d615b5ccacef87ec5ad101e",-  "size": 315779,+  "version": "1.9.81",+  "url": "https://wiki.adom.inc/download/adom/adom-desktop-puppeteer-bridge/1.9.81/adom-bridge-puppeteer-v1.9.81.zip",+  "sha256": "ae21527ca9ec1cc5e5c8d91f951c2dce8867af0906dd0ca8730160824eec9353",+  "size": 316172,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-1.9.80+1.9.81
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "1.9.80",+  "version": "1.9.81",   "description": "Drives a browser ALREADY on the machine \u2014 installed Chrome, else Microsoft Edge (every Windows PC ships with Edge) \u2014 launched with a FRESH isolated profile, so the common case has NO ~150 MB Chrome-for-Testing download and it never touches the user's real tabs/logins. Binds its local server to LOOPBACK (127.0.0.1) only, so no Windows Firewall 'allow Node through the firewall' prompt ever pops. Chrome for Testing is fetched only as a LAST RESORT if the machine has no Chromium browser at all. SPAWN-VERIFIED fallback: pup tries each detected browser (Chrome \u2192 Edge \u2192 CfT) and actually launches it, falling through to the next if one won't start (and handling browsers like Edge that relaunch onto another PID), so a corrupt/partial install never hard-fails an open. The browser that launches is cached as the default (persisted across restarts) so it isn't re-probed each time. On spawn the bridge SELF-WARMS: detects browsers + disk, and only if the box has no Chrome/Edge and no cached CfT does it background-fetch CfT so the first open is instant. browser_use pins a specific browser (chrome | edge | cft | auto); {browser:'chrome',install:true} downloads & installs REAL Google Chrome (user-scoped, no admin) on an Edge-only box. browser_readiness (READ-ONLY) reports which browser will be used + the full candidate list + the default + free disk. Every failure returns a specific errorCode + _hint (chrome_install_no_disk, chrome_download_network, chrome_install_permission, chrome_stable_not_detected, \u2026). Launches with FULL browser permissions by default for full debug (strictPermissions:true opts out). Headful automation: open/close windows+tabs, navigate, screenshot, eval JS, record. pup is a GENERIC, non-profile browser only \u2014 every session is a fresh isolated Chrome/Edge process, never the user's real signed-in browser; profile defaults to sessionId. To drive the user's REAL Chrome/Edge (their profile, cookies, SSO), use the Adom browser EXTENSION's nbrowser_* verbs \u2014 a separate bridge, not pup's job.",   "homepage": "https://wiki.adom.inc/adom/adom-desktop",   "author": "Adom Inc.",
src/server.js+19−10
@@ -1443,17 +1443,26 @@ async function killBrowserProcess(browser, profileName) {   // profile's --user-data-dir. Scoping the sweep to the profile dir makes it impossible to touch   // the user's real browser or another session's window.   if (process.platform === 'win32') {+    // v1.9.81 — MUST BE NON-BLOCKING. The v1.9.78 reap ran this CIM query with execFileSync (up to+    // 8s) SYNCHRONOUSLY on the close path, freezing Node's ENTIRE event loop for the duration.+    // PowerShell is flaky on some boxes (CIM can be slow; a bad profile drops PS to interactive and+    // it hits the timeout), so every window close could freeze the bridge for seconds. Repeated+    // freezes make the bridge unresponsive to AD's health check, which then restarts it ("the pup+    // bridge crashed") — self-inflicted, seen live after closing several test windows in a row.+    // Fire-and-forget async: the close returns immediately and the sweep runs in the background+    // without ever blocking the loop.+    const dir = path.join(PROFILES_DIR, profileName);+    const ps = `Get-CimInstance Win32_Process | Where-Object { $_.Name -match 'chrome|msedge' -and $_.CommandLine -match 'user-data-dir' -and $_.CommandLine -like '*${dir.replace(/'/g, "''")}*' } | ForEach-Object { $_.ProcessId }`;     try {-      const dir = path.join(PROFILES_DIR, profileName);-      const needle = dir.replace(/\\/g, '\\\\');-      const ps = `Get-CimInstance Win32_Process | Where-Object { $_.Name -match 'chrome|msedge' -and $_.CommandLine -match 'user-data-dir' -and $_.CommandLine -like '*${dir.replace(/'/g, "''")}*' } | ForEach-Object { $_.ProcessId }`;-      const out = execFileSync('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', ps], { encoding: 'utf8', timeout: 8000, windowsHide: true });-      const pids = (out || '').split(/\r?\n/).map(x => parseInt(x, 10)).filter(Boolean);-      if (pids.length) {-        for (const rp of pids) { try { execSync(`taskkill /F /PID ${rp}`, { stdio: 'ignore' }); } catch (e) {} }-        console.log(`[reap] profile "${profileName}": swept ${pids.length} orphaned/crashed process(es) that survived the tree kill`);-      }-    } catch (e) { /* reap is best-effort; never block a close on it */ }+      execFile('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', ps],+        { encoding: 'utf8', timeout: 8000, windowsHide: true }, (err, out) => {+          if (err) return; // best-effort; a timed-out/failed sweep must never affect the bridge+          const pids = (out || '').split(/\r?\n/).map(x => parseInt(x, 10)).filter(Boolean);+          if (!pids.length) return;+          for (const rp of pids) { try { execFile('taskkill', ['/F', '/PID', String(rp)], { windowsHide: true }, () => {}); } catch (e) {} }+          console.log(`[reap] profile "${profileName}": swept ${pids.length} orphaned/crashed process(es) that survived the tree kill`);+        });+    } catch (e) { /* never let scheduling the reap throw on the close path */ }   }    // Also check if Chrome is still locking the profile dir