Skip to content

Commit a922ec7

Browse files
committed
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.
1 parent 5113111 commit a922ec7

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/Worker/ContextWorkerPool.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ private static function killWorkers(
213213

214214
public function getWorker(): Worker
215215
{
216-
return new Internal\PooledWorker($this->pull(), $this->push);
216+
$worker = $this->pull();
217+
return new Internal\PooledWorker($worker, $this->push);
217218
}
218219

219220
/**

src/Worker/DelegatingWorkerPool.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ private function clearWaiting(\Throwable $exception): void
118118

119119
public function getWorker(): Worker
120120
{
121-
return new PooledWorker($this->selectWorker(), $this->push(...));
121+
$worker = $this->selectWorker();
122+
return new PooledWorker($worker, $this->push(...));
122123
}
123124

124125
public function getWorkerLimit(): int

0 commit comments

Comments
 (0)