mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-10 14:38:24 +08:00
feat(browse): Xvfb auto-spawn with PID + start-time validation
Adds browse/src/xvfb.ts: a Linux-only Xvfb auto-spawn module for
running headed Chromium in containers without DISPLAY. The module
walks a display range to pick a free one (never hardcodes :99) and
validates orphan PIDs by BOTH /proc/<pid>/cmdline matching 'Xvfb' AND
start-time matching the recorded value before sending any signal.
Defends against PID reuse — refuses to kill anything that doesn't
match both checks.
- shouldSpawnXvfb(env, platform) — pure decision: skip on macOS/Windows,
on Linux skip when DISPLAY or WAYLAND_DISPLAY is set (codex F2)
- pickFreeDisplay(99..120) — probes via xdpyinfo
- spawnXvfb(display) — returns { pid, startTime, display } handle
- isOurXvfb(pid, startTime) — both-checks validator
- cleanupXvfb(state) — best-effort, validates ownership before SIGTERM
Wired into server.ts startup: when shouldSpawnXvfb says yes, picks a
free display, spawns Xvfb, sets DISPLAY for chromium.launchHeaded, and
records xvfbPid/xvfbStartTime/xvfbDisplay in the state file. Cleanup
runs on process.on('exit'). The CLI's disconnect path also runs
cleanupXvfb() in the force-cleanup branch when the server is dead.
Disconnect now applies to any non-default daemon (headed mode OR
configHash-tagged daemon — i.e. one started with --proxy/--headed),
not just headed mode.
Adds xvfb + x11-utils to .github/docker/Dockerfile.ci so CI exercises
the Linux container --headed path on every run. Without it the most
common production path would go untested.
Tests: 17 new across decision logic, PID validation defenses
(cmdline mismatch, start-time mismatch), no-op safety on bad inputs,
and a Linux+Xvfb-installed gate for the spawn → validate → cleanup
round trip. Tests skip on macOS/Windows automatically.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
7
.github/docker/Dockerfile.ci
vendored
7
.github/docker/Dockerfile.ci
vendored
@@ -77,8 +77,13 @@ RUN npx playwright install-deps chromium
|
||||
# render in DejaVu Sans. playwright install-deps happens to pull this in today,
|
||||
# but the dep is implicit and could change — install explicitly so upgrades
|
||||
# can't silently regress rendering.
|
||||
#
|
||||
# Xvfb is also installed here so the browse --headed integration tests
|
||||
# (headed-xvfb, headed-orphan-cleanup) can exercise the Linux container
|
||||
# auto-spawn path on every CI run. Without Xvfb in the image, the most
|
||||
# common production --headed path goes untested.
|
||||
RUN for i in 1 2 3; do \
|
||||
apt-get update && apt-get install -y --no-install-recommends fonts-liberation fontconfig && break || \
|
||||
apt-get update && apt-get install -y --no-install-recommends fonts-liberation fontconfig xvfb x11-utils && break || \
|
||||
(echo "fonts-liberation install retry $i/3"; sleep 10); \
|
||||
done \
|
||||
&& fc-cache -f \
|
||||
|
||||
Reference in New Issue
Block a user