← Commit history

EADDRINUSE self-heal for the 557 permanent-outage loop: when a replacement pup spawn finds its port held, it probes the holder's /health and, only if the holder identifies as a sibling pup bridge (by definition an orphan ab lost track of), kills that one pid and retries the bind with a 3-attempt cap; a non-pup holder is never touched and the process exits with a clear log. Turns the reaper-lost-my-pid outage from a manual taskkill into automatic recovery on the next verb

John Lauer ·d7c05d1f7b ·2mo ago ·parent 9b11632
4 files changed +59−7
adom-bridge-puppeteer-manifest.json+4−4
@@ -1,10 +1,10 @@ {   "manifest_version": 1,   "name": "puppeteer",-  "version": "2.0.15",-  "url": "https://wiki.adom.inc/download/adom/pup-bridge/2.0.15/adom-bridge-puppeteer-v2.0.15.zip",-  "sha256": "35cf2ce8e3e741001ed67b9b1955d3e44ed02798689b9737656737a354dc3deb",-  "size": 641803,+  "version": "2.0.16",+  "url": "https://wiki.adom.inc/download/adom/pup-bridge/2.0.16/adom-bridge-puppeteer-v2.0.16.zip",+  "sha256": "04e9d602d07b2b124c31baaff2d0564cffc22b0393931f669e8bc5fe934f3fc2",+  "size": 642918,   "verbPrefixes": [     "browser_",     "desktop_recorder_",
src/BRIDGE_VERSION+1−1
@@ -1 +1 @@-2.0.15+2.0.16
src/bridge.json+1−1
@@ -2,7 +2,7 @@   "manifest_version": 1,   "name": "puppeteer",   "displayName": "Puppeteer (Chrome for Testing + Native)",-  "version": "2.0.15",+  "version": "2.0.16",   "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. pup_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. pup_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. macOS (v1.9.74+): full parity with mac-native mechanics \u2014 background-by-default is the app-level hide (windows stay drivable/screenshottable while hidden), raise/lower map to unhide+activate/hide, pup_alert_window posts a native toast whose click focuses the window, pup_use {browser:'chrome',install:true} installs Chrome from the official dmg, and taskbar identity/badging remains Windows-only.",   "homepage": "https://wiki.adom.inc/adom/adom-bridge",   "author": "Adom Inc.",
src/server.js+53−1
@@ -14269,7 +14269,9 @@ server.keepAliveTimeout = 30_000; // binds every interface and pops the Windows Firewall "allow access?" dialog; honoring // ADOM_BIND_HOST keeps a loopback-only socket, which is firewall-exempt. const BIND_HOST = process.env.ADOM_BIND_HOST || '127.0.0.1';-server.listen(PORT, BIND_HOST, async () => {+let _pupBoundOnce = false;+const _onPupBound = async () => {+  if (_pupBoundOnce) return; _pupBoundOnce = true;   console.log(`Puppeteer Bridge running on http://${BIND_HOST}:${PORT} (bind=${BIND_HOST}; no firewall prompt)`);   console.log('Multi-session support: sessions are tabs sharing Chrome profiles via userDataDir');   console.log('Endpoints: /health, /command, /launch, /navigate, /reload, /screenshot, /screenshot.png, /errors, /eval, /wait, /status, /close');@@ -14620,8 +14622,58 @@ server.listen(PORT, BIND_HOST, async () => {       }     }   }, 5 * 60 * 1000);+};++// v2.0.16 (#557 ask 3, pup-side defense): EADDRINUSE SELF-HEAL. The #557 permanent outage was ab's+// reaper losing track of a live bridge process (bridge_kill returned killedPids:[]): the orphan kept+// port 64230, so every replacement ab spawned died on the bind conflict, forever, and recovery took a+// manual taskkill. ab's real fix (reap by port owner / child tree) is filed against adom/adom-bridge;+// until it lands, the REPLACEMENT heals it: on EADDRINUSE, probe the holder's /health — if (and ONLY+// if) it identifies as a pup puppeteer bridge, it is by definition an orphan (ab only spawns a+// replacement when the holder is off its books), so kill that ONE pid and retry the bind. A holder+// that is NOT a pup bridge is never touched: log and exit. Convergence: if ab tracks us after the+// heal, routing resumes; if ab already gave up on us, the NEXT spawn heals against us and gets+// tracked — one extra cycle, never a loop (3-retry cap either way).+let _bindRetries = 0;+server.on('error', (err) => {+  const code = err && err.code;+  if (code !== 'EADDRINUSE' || process.platform !== 'win32' || _bindRetries >= 3) {+    console.error(`[bind] fatal listen error (${code || (err && err.message)}) — exiting so the supervisor respawns cleanly`);+    process.exit(1);+  }+  _bindRetries++;+  (async () => {+    try {+      const health = await Promise.race([+        fetch(`http://127.0.0.1:${PORT}/health`).then(r => r.json()).catch(() => null),+        new Promise(r => setTimeout(() => r(null), 2500)),+      ]);+      if (!health || health.bridge !== 'puppeteer') {+        console.error(`[bind] port ${PORT} is held by a NON-pup process — refusing to touch it; exiting`);+        process.exit(1);+      }+      const { execFileSync } = require('child_process');+      const pidOut = execFileSync('powershell.exe', ['-NoProfile', '-Command',+        `Get-NetTCPConnection -LocalPort ${PORT} -State Listen -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty OwningProcess`],+        { encoding: 'utf8', timeout: 8000, windowsHide: true }).trim();+      const holderPid = Number(pidOut) || 0;+      if (!holderPid || holderPid === process.pid) {+        console.error(`[bind] EADDRINUSE but no resolvable holder pid (got "${pidOut}") — retrying bind blind`);+      } else {+        console.error(`[bind] port ${PORT} held by ORPHANED sibling pup bridge v${health.version || '?'} (pid ${holderPid}) — ab spawned this process as its replacement, so the holder is off ab's books. Killing that ONE pid and retrying (attempt ${_bindRetries}/3).`);+        execFileSync('taskkill', ['/PID', String(holderPid), '/F'], { timeout: 8000, windowsHide: true });+      }+      await new Promise(r => setTimeout(r, 1200));+      server.listen(PORT, BIND_HOST, _onPupBound);+    } catch (e) {+      console.error(`[bind] self-heal attempt ${_bindRetries} failed: ${e.message} — exiting for a clean respawn`);+      process.exit(1);+    }+  })(); }); +server.listen(PORT, BIND_HOST, _onPupBound);+ // ════════════════════════════════════════════════════════════════════════════ //  RECORDING — desktop (HUD) and tab (CDP screencast) // ════════════════════════════════════════════════════════════════════════════