Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix finished process handling in PHP 8.1.22/8.2.9 #212

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions src/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,28 +306,47 @@ protected function registerListener()
pcntl_async_signals(true);

pcntl_signal(SIGCHLD, function ($signo, $status) {
/**
* PHP 8.1.22 and 8.2.9 changed SIGCHLD handling:
* https://github.com/php/php-src/pull/11509
* This changes pcntl_waitpid() at the same time, so it requires special handling.
*
* It was reverted already and probably won't work in any other PHP version.
* https://github.com/php/php-src/pull/11863
*/
if (phpversion() === '8.1.22' || phpversion() === '8.2.9') {
$this->handleFinishedProcess($status['pid'], $status['status']);

return;
}

while (true) {
$pid = pcntl_waitpid(-1, $processState, WNOHANG | WUNTRACED);

if ($pid <= 0) {
break;
}

$process = $this->inProgress[$pid] ?? null;
$this->handleFinishedProcess($pid, $status['status']);
}
});
}

if (! $process) {
continue;
}
protected function handleFinishedProcess(int $pid, int $status)
{
$process = $this->inProgress[$pid] ?? null;

if ($status['status'] === 0) {
$this->markAsFinished($process);
if (! $process) {
return;
}

continue;
}
if ($status === 0) {
$this->markAsFinished($process);

$this->markAsFailed($process);
}
});
return;
}

$this->markAsFailed($process);
}

public function stop()
Expand Down
Loading