From 982ab5ad13446d1fab79e463afad7db4835d32af Mon Sep 17 00:00:00 2001 From: Julian Vennen Date: Mon, 29 Jun 2026 14:51:12 +0200 Subject: [PATCH] Handle proc_open failing and closing RuntimeProcesses that failed to start correctly --- src/Runtime/RuntimeProcess.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Runtime/RuntimeProcess.php b/src/Runtime/RuntimeProcess.php index 5f92c93..0ea59b0 100644 --- a/src/Runtime/RuntimeProcess.php +++ b/src/Runtime/RuntimeProcess.php @@ -6,6 +6,7 @@ use Aternos\Taskmaster\Communication\Socket\SocketPair; use Aternos\Taskmaster\Communication\StdStreams; use Aternos\Taskmaster\TaskmasterOptions; +use RuntimeException; /** * Class RuntimeProcess @@ -46,6 +47,9 @@ public function __construct(TaskmasterOptions $options, string $runtimeClass) 2 => $stdStreams->getStderr(), 3 => $socketPair->getChildSocket()->getStream(), ], $pipes); + if (!$this->process) { + throw new RuntimeException("Could not open process."); + } $socketPair->closeChildSocket(); } @@ -57,6 +61,9 @@ public function __construct(TaskmasterOptions $options, string $runtimeClass) public function stop(): bool { $this->socket->close(); + if (!$this->process) { + return false; + } $result = proc_terminate($this->process); proc_close($this->process); $this->process = null;