mirror of
https://github.com/daijro/camoufox.git
synced 2026-11-19 00:07:28 +00:00
Stop Xvfb when the process that launched it dies (#868)
headless="virtual" started Xvfb in its own session and stopped it only on the browser's close path. A launcher ended by a signal (timeout, a supervisor, a cancelled CI job) never reaches that path, so its Xvfb ran forever, together with the session bus and desktop helpers Firefox autolaunched on that display. Both packages now exec Xvfb through `setpriv --pdeathsig TERM`, so the kernel signals it when its launcher dies, even by SIGKILL. SIGTERM lets Xvfb remove its own lock and socket, and the autolaunched bus exits when it loses its X connection. setpriv comes from util-linux. The leak suite missed this because every crash test keeps the launcher alive to tear down, and leak_check follows only our descendants, which an orphan no longer is. test_launcher_sigkill_leaves_nothing_on_its_display kills the launcher and looks machine-wide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6f74fa06df
commit
9f94b0ea46
@@ -87,6 +87,13 @@ class VirtualDisplay:
|
||||
raise CannotExecuteXvfb(f"I do not have permission to execute Xvfb: {path}")
|
||||
return path
|
||||
|
||||
@property
|
||||
def setpriv_path(self) -> str:
|
||||
path = which("setpriv")
|
||||
if not path:
|
||||
raise CannotFindXvfb("Please install util-linux (for setpriv) to use headless mode.")
|
||||
return path
|
||||
|
||||
def get(self) -> str:
|
||||
self._assert_linux()
|
||||
|
||||
@@ -97,7 +104,14 @@ class VirtualDisplay:
|
||||
# the child (unlike Node's `stdio: [..., 'pipe']` which renumbers
|
||||
# to 3), so we tell Xvfb that exact number.
|
||||
read_fd, write_fd = os.pipe()
|
||||
cmd = [self.xvfb_path, "-displayfd", str(write_fd), *self.xvfb_args]
|
||||
# setpriv's parent-death signal stops Xvfb when this process dies
|
||||
# without reaching kill(), even by SIGKILL; SIGTERM lets Xvfb remove
|
||||
# its own lock and socket. See xvfb-dies-with-its-launcher in
|
||||
# ci/tribal-rules.yml.
|
||||
cmd = [
|
||||
self.setpriv_path, "--pdeathsig", "TERM",
|
||||
self.xvfb_path, "-displayfd", str(write_fd), *self.xvfb_args,
|
||||
]
|
||||
if self.debug:
|
||||
print("Starting virtual display:", " ".join(cmd))
|
||||
self.proc = subprocess.Popen( # nosec
|
||||
|
||||
Reference in New Issue
Block a user