Skip to content

fix(vnc): detect Xvfb via /tmp/.X11-unix socket, not ps regex - #8070

Closed
luxles wants to merge 1 commit into
jo-inc:masterfrom
luxles:fix/vnc-watcher-socket-detect
Closed

fix(vnc): detect Xvfb via /tmp/.X11-unix socket, not ps regex#8070
luxles wants to merge 1 commit into
jo-inc:masterfrom
luxles:fix/vnc-watcher-socket-detect

Conversation

@luxles

@luxles luxles commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Bug

plugins/vnc/vnc-watcher.sh detects the Camoufox Xvfb display with:

FOUND=$(ps -eo args= 2>/dev/null | awk -v res="$VNC_RESOLUTION" '
    /\\/Xvfb :[0-9]+/ && index($0, res) {
      for (i=1;i<=NF;i++) if ($i ~ /^:[0-9]+$/) { print $i; exit }
    }
  ' | head -1)

This regex requires the literal :N token (e.g. Xvfb :0 ...) in Xvfb's ps args.

But Camoufox launches Xvfb with -displayfd 3 (e.g. Xvfb -displayfd 3 -screen 0 1920x1080x24 ...). In that mode the display number is not present as a literal :N token in ps args — it is allocated by Xvfb and exposed only as the /tmp/.X11-unix/X0 socket.

→ With -displayfd 3, FOUND is always empty → the watcher never launches x11vnc → port 5900 never listens, VNC stays black.

Fix

Detect the display via the /tmp/.X11-unix/X* socket (mode-independent — works for both :N literal launches and -displayfd N launches):

FOUND=""
for sock in /tmp/.X11-unix/X*; do
  [ -e "$sock" ] || continue
  DISP_NUM=$(basename "$sock" | sed 's/^X//')
  echo "$DISP_NUM" | grep -qE '^[0-9]+$' || continue
  # Crucial fix: verify it's a socket, not the X11-unix directory
  [ -S "$sock" ] || continue
  FOUND=":$DISP_NUM"
  break
done

Equivalent result to the original regex (yields :0), but also works when Xvfb is started with -displayfd 3.

Verification

  • Environment: Camoufox launched as Xvfb -displayfd 3 -screen 0 1920x1080x24 ...
  • Before fix: watcher log stops at VNC watcher started -- will attach x11vnc when Camoufox's Xvfb appears; 5900 never listens.
  • After fix: when /tmp/.X11-unix/X0 appears, FOUND=:0, x11vnc launches, 5900 listens, noVNC (6080) connects.

Scope note (no overclaim)

This PR fixes only the display-detection regex not matching the -displayfd 3 launch mode.
Note there is a separate, orthogonal issue: some locally-built camofox-browser:135.0.1-x86_64 images fail to start the browser at all in certain environments (noVNC missing from image, UBO addon download fails, cannot open display: [object Promise] = the await VirtualDisplay.get() bug). That is a different root cause and is not addressed by this PR.

Related

The watcher detects the Xvfb display via:
  FOUND=$(ps -eo args= | awk '/\\/Xvfb :[0-9]+/ ...')

This regex requires a literal ':N' token in Xvfb's ps args.
But Camoufox launches Xvfb with '-displayfd 3', where the
display number is NOT present as a ':N' token in ps args
(it is allocated by Xvfb and exposed only as the
/tmp/.X11-unix/X0 socket).

Switch detection to scanning /tmp/.X11-unix/X* sockets
(with [ -S ] guard). Works for both :N literal launches
and -displayfd N launches.
skyfallsin added a commit that referenced this pull request Jul 19, 2026
Incorporates the VNC attachment and recovery work proposed in #4781, #5243, #6549, and #8070 while preserving per-server process ownership.

Co-authored-by: Doud-FR <59610009+Doud-FR@users.noreply.github.com>
Co-authored-by: paranoidi <504877+paranoidi@users.noreply.github.com>
Co-authored-by: Omar Usman <19397228+modanq@users.noreply.github.com>
Co-authored-by: luxles <291718194+luxles@users.noreply.github.com>
@skyfallsin

Copy link
Copy Markdown
Contributor

Thank you — the -displayfd attachment fix has shipped in v1.12.1. The released implementation keeps the socket-based behavior while mapping the socket back to the watcher-owned Xvfb PID, so multiple Camofox servers cannot attach to each other’s displays. It also includes same-display x11vnc recovery and a Linux smoke test.

Included via commit 50b5031 with co-author credit.

@skyfallsin skyfallsin closed this Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants