From 71fe02899fa15c7ed20c3d1afa67f48fe11d947e Mon Sep 17 00:00:00 2001 From: Praveen Senpai Date: Mon, 22 Jun 2026 20:55:48 +0530 Subject: [PATCH] fix: kill Xvfb with SIGKILL and clean up X11 lock/socket files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the terminate→wait→kill fallback in VirtualDisplay.kill() with a direct SIGKILL to prevent zombie Xvfb processes. After the process exits, remove the stale /tmp/.X{n}-lock and /tmp/.X11-unix/X{n} files so future display allocations are not blocked. Also set self.proc = None to mark the display as fully cleaned up. --- pythonlib/camoufox/virtdisplay.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pythonlib/camoufox/virtdisplay.py b/pythonlib/camoufox/virtdisplay.py index 85da150..5846d8c 100644 --- a/pythonlib/camoufox/virtdisplay.py +++ b/pythonlib/camoufox/virtdisplay.py @@ -1,4 +1,5 @@ import os +import signal import select import subprocess # nosec import time @@ -115,14 +116,20 @@ class VirtualDisplay: if self.proc and self.proc.poll() is None: if self.debug: print("Terminating virtual display:", self._display) - self.proc.terminate() try: + self.proc.send_signal(signal.SIGKILL) self.proc.wait(timeout=5) - except subprocess.TimeoutExpired: - if self.debug: - print("Xvfb did not exit in time, killing forcefully") - self.proc.kill() - self.proc.wait() + except Exception: + pass + try: + os.remove(f"/tmp/.X{self._display}-lock") + except FileNotFoundError: + pass + try: + os.remove(f"/tmp/.X11-unix/X{self._display}") + except FileNotFoundError: + pass + self.proc = None @staticmethod def _assert_linux() -> None: