From 84fadb7481263e30602400a38c43bcd38dda6473 Mon Sep 17 00:00:00 2001 From: Pratyush Sharma <56130065+pratyush618@users.noreply.github.com> Date: Wed, 15 Jul 2026 18:31:52 +0530 Subject: [PATCH] Report server exit code instead of pipe error When the node server exits early, writing its config to the dead stdin raised BrokenPipeError (EINVAL on Windows), burying the real cause. communicate() ignores both, so the underlying failure stays visible. Refs #656 --- pythonlib/camoufox/server.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pythonlib/camoufox/server.py b/pythonlib/camoufox/server.py index 0f9b856..d3e7b23 100644 --- a/pythonlib/camoufox/server.py +++ b/pythonlib/camoufox/server.py @@ -63,13 +63,12 @@ def launch_server(**kwargs) -> NoReturn: stdin=subprocess.PIPE, text=True, ) - # Write data to stdin and close the stream - if process.stdin: - process.stdin.write(base64.b64encode(data).decode()) - process.stdin.close() - - # Wait forever - process.wait() + # Write data to stdin, close the stream, and wait forever. + # communicate() tolerates the pipe closing early if the server exits before reading + # its config, keeping that error visible instead of masking it with an OSError. + process.communicate(input=base64.b64encode(data).decode()) # Add an explicit return statement to satisfy the NoReturn type hint - raise RuntimeError("Server process terminated unexpectedly") + raise RuntimeError( + f"Server process terminated unexpectedly with exit code {process.returncode}" + )