Skip to content

Commit

Permalink
Avoid PHP object allocation issue
Browse files Browse the repository at this point in the history
PooledWorker::__destruct() is run even if $this->selectWorker() never returns because the object is allocated prior to the constructor call.
  • Loading branch information
trowski committed Feb 8, 2025
1 parent 5113111 commit a922ec7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Worker/ContextWorkerPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Worker/DelegatingWorkerPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a922ec7

Please sign in to comment.