From a922ec764d588d5a44f3453215dad7bc86fede8b Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sat, 8 Feb 2025 09:02:53 -0600 Subject: [PATCH] Avoid PHP object allocation issue PooledWorker::__destruct() is run even if $this->selectWorker() never returns because the object is allocated prior to the constructor call. --- src/Worker/ContextWorkerPool.php | 3 ++- src/Worker/DelegatingWorkerPool.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Worker/ContextWorkerPool.php b/src/Worker/ContextWorkerPool.php index 4962d9d..e7f916b 100644 --- a/src/Worker/ContextWorkerPool.php +++ b/src/Worker/ContextWorkerPool.php @@ -213,7 +213,8 @@ private static function killWorkers( public function getWorker(): Worker { - return new Internal\PooledWorker($this->pull(), $this->push); + $worker = $this->pull(); + return new Internal\PooledWorker($worker, $this->push); } /** diff --git a/src/Worker/DelegatingWorkerPool.php b/src/Worker/DelegatingWorkerPool.php index 129f7de..f3822c3 100644 --- a/src/Worker/DelegatingWorkerPool.php +++ b/src/Worker/DelegatingWorkerPool.php @@ -118,7 +118,8 @@ private function clearWaiting(\Throwable $exception): void public function getWorker(): Worker { - return new PooledWorker($this->selectWorker(), $this->push(...)); + $worker = $this->selectWorker(); + return new PooledWorker($worker, $this->push(...)); } public function getWorkerLimit(): int