From 28a58646f7a8b8ea57b90bbfb2366842dcc7174f Mon Sep 17 00:00:00 2001 From: mucha55 Date: Tue, 14 Jan 2020 09:17:40 -0600 Subject: [PATCH 1/2] KOJO-180 | Clean up Root's Process Pool after JSCLP exit --- src/Process/Pool/Strategy.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Process/Pool/Strategy.php b/src/Process/Pool/Strategy.php index 406c19d2..ac30df6a 100644 --- a/src/Process/Pool/Strategy.php +++ b/src/Process/Pool/Strategy.php @@ -21,7 +21,7 @@ public function childProcessExited(ProcessInterface $process): StrategyInterface } elseif ($process instanceof ListenerInterface) { $this->_listenerProcessExited($process); } elseif ($process instanceof JobStateChangelogProcessorInterface) { - // A new STL process will be created by the Root when appropriate + $this->_jobStateChangelogProcessorProcessExited($process); } else { $className = get_class($process); throw new \UnexpectedValueException("Unexpected process class[$className]."); @@ -98,6 +98,20 @@ protected function _jobProcessExited(JobInterface $jobProcess): Strategy return $this; } + protected function _jobStateChangelogProcessorProcessExited(JobStateChangelogProcessorInterface $jsclpProcess) : Strategy + { + $this->_getProcessPool()->freeChildProcess($jsclpProcess->getProcessId()); + + // usually this is where we'd spawn a new JSCLP to take the place of the one that exited, but + // that is handled by \Neighborhoods\Kojo\Process\Root::pollSingletonProcesses() + + if (!$this->_getProcessPool()->hasAlarm()) { + $this->_getProcessPool()->setAlarm($this->getMaxAlarmTime()); + } + + return $this; + } + public function receivedAlarm(): StrategyInterface { if (!$this->_getProcessPool()->isFull() && $this->_getProcessPool()->canEnvironmentSustainAdditionProcesses()) { From e60aa1f9e8c2530c8eef6a0d028ee7239cd1fe11 Mon Sep 17 00:00:00 2001 From: mucha55 Date: Tue, 14 Jan 2020 09:56:18 -0600 Subject: [PATCH 2/2] KOJO-178 | Guard against full process pool when Root is polling singletons --- src/Process/Root.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Process/Root.php b/src/Process/Root.php index 41d65026..c5f08663 100644 --- a/src/Process/Root.php +++ b/src/Process/Root.php @@ -43,7 +43,9 @@ protected function pollSingletonProcesses() : Root if ($semaphoreResource->testLock()) { try { $process = $this->_getProcessCollection()->getProcessPrototypeClone($singletonType); - $this->_getProcessPool()->addChildProcess($process); + if (!$this->_getProcessPool()->isFull()) { + $this->_getProcessPool()->addChildProcess($process); + } } catch (Forked\Exception $forkedException) { // this is fine, another execution environment will spawn this process // TODO: consider breaking here to stop attempting to spawn other singletons