From 957b2b1b65ab140e8536f8ec34cc4cd202bb3f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojta=20Mat=C4=9Bjka?= Date: Fri, 25 Oct 2019 14:03:49 +0200 Subject: [PATCH 1/3] Error handling of Unexpected termination of child Handle Unexpected child termination and keep number of processes upper Options::MIN_SIZE --- src/Manager/Flexible.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Manager/Flexible.php b/src/Manager/Flexible.php index fe1e3b2..1c5fada 100644 --- a/src/Manager/Flexible.php +++ b/src/Manager/Flexible.php @@ -6,6 +6,7 @@ use React\EventLoop\LoopInterface; use WyriHaximus\React\ChildProcess\Messenger\Messages\Message; use WyriHaximus\React\ChildProcess\Messenger\Messenger; +use WyriHaximus\React\ChildProcess\Messenger\ProcessUnexpectedEndException; use WyriHaximus\React\ChildProcess\Pool\ManagerInterface; use WyriHaximus\React\ChildProcess\Pool\Options; use WyriHaximus\React\ChildProcess\Pool\ProcessCollectionInterface; @@ -87,7 +88,11 @@ protected function spawn() $worker->on('message', function ($message) { $this->emit('message', [$message]); }); - $worker->on('error', function ($error) { + $worker->on('error', function ($error) use ($worker) { + if($error instanceof ProcessUnexpectedEndException){ + $worker->terminate(); + $this->ping(); + } $this->emit('error', [$error]); }); $this->workerAvailable($worker); @@ -115,6 +120,13 @@ protected function spawnAndGetMessenger(callable $current) public function ping() { + if (count($this->workers) + $this->startingProcesses < $this->options[Options::MIN_SIZE]) { + for($i = count($this->workers) + $this->startingProcesses; $i <= $this->options[Options::MIN_SIZE]; $++){ + $this->spawn(); + } + return; + } + foreach ($this->workers as $worker) { if (!$worker->isBusy()) { $this->workerAvailable($worker); @@ -122,11 +134,6 @@ public function ping() } } - if (count($this->workers) + $this->startingProcesses < $this->options[Options::MIN_SIZE]) { - $this->spawn(); - return; - } - if (count($this->workers) + $this->startingProcesses < $this->options[Options::MAX_SIZE]) { $this->spawn(); } From c5aa36f71b2b0d3539616fa46ebb4584c95e2b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojta=20Mat=C4=9Bjka?= Date: Tue, 29 Oct 2019 14:04:57 +0100 Subject: [PATCH 2/3] Update to coding standard --- src/Manager/Flexible.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Manager/Flexible.php b/src/Manager/Flexible.php index 1c5fada..0d1722f 100644 --- a/src/Manager/Flexible.php +++ b/src/Manager/Flexible.php @@ -89,7 +89,7 @@ protected function spawn() $this->emit('message', [$message]); }); $worker->on('error', function ($error) use ($worker) { - if($error instanceof ProcessUnexpectedEndException){ + if ($error instanceof ProcessUnexpectedEndException) { $worker->terminate(); $this->ping(); } @@ -121,7 +121,7 @@ protected function spawnAndGetMessenger(callable $current) public function ping() { if (count($this->workers) + $this->startingProcesses < $this->options[Options::MIN_SIZE]) { - for($i = count($this->workers) + $this->startingProcesses; $i <= $this->options[Options::MIN_SIZE]; $++){ + for ($i = count($this->workers) + $this->startingProcesses; $i <= $this->options[Options::MIN_SIZE]; $++) { $this->spawn(); } return; From 26e74e329385d7fe1e87f30e40cc1c295317542c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojta=20Mat=C4=9Bjka?= Date: Fri, 13 Dec 2019 08:44:31 +0100 Subject: [PATCH 3/3] Update src/Manager/Flexible.php Parse error fixed Co-Authored-By: Cees-Jan Kiewiet --- src/Manager/Flexible.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Manager/Flexible.php b/src/Manager/Flexible.php index 0d1722f..c044155 100644 --- a/src/Manager/Flexible.php +++ b/src/Manager/Flexible.php @@ -121,7 +121,7 @@ protected function spawnAndGetMessenger(callable $current) public function ping() { if (count($this->workers) + $this->startingProcesses < $this->options[Options::MIN_SIZE]) { - for ($i = count($this->workers) + $this->startingProcesses; $i <= $this->options[Options::MIN_SIZE]; $++) { + for ($i = count($this->workers) + $this->startingProcesses; $i <= $this->options[Options::MIN_SIZE]; $i++) { $this->spawn(); } return;