Skip to content

Commit

Permalink
Ensure propper cleanup if the parent process of a spinner is terminated
Browse files Browse the repository at this point in the history
  • Loading branch information
freost committed Oct 26, 2024
1 parent 3261fdb commit cb71104
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mako/application/cli/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ protected function startReactor(): void
// Ensure that the cursor and stty are restored in case of a SIGINT call

if ($signalHandler->canHandleSignals()) {
$signalHandler->addHandler(SIGINT, function ($signal, $isLast) use ($output): void {
$signalHandler->addHandler([SIGINT, SIGTERM], function ($signal, $isLast) use ($output): void {
$output->getCursor()->restore();
$output->getEnvironment()->restoreStty();

// If we're the last handler then we exit with status code 130 (SIGINT)
// If we're the last handler then we exit with status code 130 (SIGINT) or 143 (SIGTERM)

if ($isLast) {
exit(130);
exit(128 + $signal);
}
});
}
Expand Down
4 changes: 4 additions & 0 deletions src/mako/cli/output/helpers/Spinner.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ protected function spinner(string $message, string $template): void
if (posix_kill(posix_getpid(), 0) === false) {
break;
}

if (posix_getppid() === 1) {
posix_kill(posix_getpid(), SIGKILL);
}
}
}

Expand Down

0 comments on commit cb71104

Please sign in to comment.