From 96491ebfe103cd62a596a3319cba8fa347f2c680 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Wed, 20 Sep 2017 10:32:13 +0200 Subject: [PATCH] Fix hanging if process is destroyed during startup --- lib/Internal/Windows/SocketConnector.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Internal/Windows/SocketConnector.php b/lib/Internal/Windows/SocketConnector.php index 00de786..97a0748 100644 --- a/lib/Internal/Windows/SocketConnector.php +++ b/lib/Internal/Windows/SocketConnector.php @@ -229,12 +229,16 @@ final class SocketConnector { return; } - $handle->status = ProcessStatus::RUNNING; $handle->pidDeferred->resolve($packet['pid']); - $handle->exitCodeWatcher = Loop::onReadable($handle->sockets[0], [$this, 'onReadableExitCode'], $handle); - if (!$handle->exitCodeRequested) { - Loop::unreference($handle->exitCodeWatcher); + // Required, because a process might be destroyed while starting + if ($handle->status === ProcessStatus::STARTING) { + $handle->status = ProcessStatus::RUNNING; + $handle->exitCodeWatcher = Loop::onReadable($handle->sockets[0], [$this, 'onReadableExitCode'], $handle); + + if (!$handle->exitCodeRequested) { + Loop::unreference($handle->exitCodeWatcher); + } } unset($this->pendingProcesses[$handle->wrapperPid]);