Fix watchdog relaunch-loop: guard before relaunch, main-process PID filter
The relaunch-loop guard only protected the kill step, not the relaunch. When CDP was unreachable on a slow-starting browser, the watchdog would invoke netvm-chrome.sh (which kills the existing browser) before checking if it was recently launched — piling up 5 chromiums on opm. Now the <120s check runs before the relaunch and skips the entire cycle. Also fixed the PID check to match only the main browser process (--remote-debugging-port, excluding --type= renderer/gpu children). Session: sidechat/chromebox-ops
This commit is contained in:
@@ -75,12 +75,21 @@ if healthy; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "unhealthy ($HEALTH_FAIL_REASON), relaunching chromebox"
|
# Relaunch-loop guard (2026-10-04): if the main browser for this profile
|
||||||
# Kill-loop guard (2026-10-04): if a chromium for this profile launched <2 min
|
# launched <2 min ago it's probably still starting up (CDP not yet bound).
|
||||||
# ago it's probably still loading the page — killing it just restarts the
|
# Relaunching now would kill a healthy-but-slow cold start via netvm-chrome.sh
|
||||||
# loop (observed: 646 killed twice while the page was still loading).
|
# and reset the startup clock every cycle (observed: opm piled up 5 chromiums
|
||||||
|
# because the guard only protected the kill step, not the relaunch). Skip the
|
||||||
|
# entire cycle instead.
|
||||||
|
# NOTE: match only the main browser process (--remote-debugging-port present,
|
||||||
|
# no --type= flag). Renderer/gpu children (--type=renderer etc.) start later
|
||||||
|
# than the main process and must not satisfy this check.
|
||||||
recent_pid=""
|
recent_pid=""
|
||||||
for _pid in $(pgrep -f "chromium.*profiles/${PROFILE}/" 2>/dev/null); do
|
for _pid in $(pgrep -f "chromium.*--remote-debugging-port=${CDP_PORT}([[:space:]]|$)" 2>/dev/null); do
|
||||||
|
# Skip child processes (renderer, gpu, etc.) — only the main browser counts
|
||||||
|
if ps -o args= -p "$_pid" 2>/dev/null | grep -q -- "--type="; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
_start=$(date -d "$(ps -o lstart= -p "$_pid" 2>/dev/null)" +%s 2>/dev/null || echo 0)
|
_start=$(date -d "$(ps -o lstart= -p "$_pid" 2>/dev/null)" +%s 2>/dev/null || echo 0)
|
||||||
_now=$(date +%s)
|
_now=$(date +%s)
|
||||||
if [ $(( _now - _start )) -lt 120 ] && [ "$_start" -gt 0 ]; then
|
if [ $(( _now - _start )) -lt 120 ] && [ "$_start" -gt 0 ]; then
|
||||||
@@ -89,9 +98,10 @@ for _pid in $(pgrep -f "chromium.*profiles/${PROFILE}/" 2>/dev/null); do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ -n "$recent_pid" ]; then
|
if [ -n "$recent_pid" ]; then
|
||||||
log "browser launched recently (pid $recent_pid), skipping kill (probably still starting)"
|
log "browser launched recently (pid $recent_pid), skipping relaunch (probably still starting)"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
log "unhealthy ($HEALTH_FAIL_REASON), relaunching chromebox"
|
||||||
# bracket trick so pkill never matches its own command line
|
# bracket trick so pkill never matches its own command line
|
||||||
pat="profiles/${PROFILE:0:${#PROFILE}-1}[${PROFILE: -1}]/"
|
pat="profiles/${PROFILE:0:${#PROFILE}-1}[${PROFILE: -1}]/"
|
||||||
pkill -f "chromium.*$pat" 2>/dev/null || true
|
pkill -f "chromium.*$pat" 2>/dev/null || true
|
||||||
|
|||||||
Reference in New Issue
Block a user