Skip to content

Commit 614d540

Browse files
committed
When a process is exiting, proc_get_status (waitpid) may still show the process running for a short period after stdout is closed. A 0.1 second timer is enough to skip the race condition
1 parent fbe0d68 commit 614d540

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Scheduler.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,13 @@ public function setup_input_process(Process $process, int|string $id): void
465465
*/
466466
$process->stdout->on('close', function() use ($id, $process) {
467467
if (!$this->state->isStopping() && $process->isRunning()) {
468-
$this->logger->critical("{id} STDOUT closed unexpectedly, terminating process", ['id' => $id,]);
469-
$process->terminate(SIGTERM);
468+
//Use a timer to get around a race condition in Alpine linux where the process hasn't been reaped yet (SIGCHLD delayed?)
469+
$this->loop->addTimer(0.1, function() use ($id, $process) {
470+
if ($process->isRunning()) {
471+
$this->logger->critical("{id} STDOUT closed unexpectedly, terminating process", ['id' => $id,]);
472+
$process->terminate(SIGTERM);
473+
}
474+
});
470475
}
471476
});
472477

0 commit comments

Comments
 (0)