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}" + )