1
0
Fork 0

Ensure signalHandler is kept around and unregistered

pull/10965/head
Jordi Boggiano 2022-07-22 10:36:27 +02:00
parent 4aa3258d19
commit f0ab518c46
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 14 additions and 6 deletions

View File

@ -81,6 +81,9 @@ class Application extends BaseApplication
*/ */
private $initialWorkingDirectory; private $initialWorkingDirectory;
/** @var SignalHandler */
private $signalHandler;
public function __construct() public function __construct()
{ {
static $shutdownRegistered = false; static $shutdownRegistered = false;
@ -96,13 +99,13 @@ class Application extends BaseApplication
$this->io = new NullIO(); $this->io = new NullIO();
if (!$shutdownRegistered) { $this->signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) {
$signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) {
$this->io->writeError('Received '.$signal.', aborting', true, IOInterface::DEBUG); $this->io->writeError('Received '.$signal.', aborting', true, IOInterface::DEBUG);
$handler->exitWithLastSignal(); $handler->exitWithLastSignal();
}); });
if (!$shutdownRegistered) {
$shutdownRegistered = true; $shutdownRegistered = true;
register_shutdown_function(static function (): void { register_shutdown_function(static function (): void {
@ -121,6 +124,11 @@ class Application extends BaseApplication
parent::__construct('Composer', Composer::getVersion()); parent::__construct('Composer', Composer::getVersion());
} }
public function __destruct()
{
$this->signalHandler->unregister();
}
public function run(InputInterface $input = null, OutputInterface $output = null): int public function run(InputInterface $input = null, OutputInterface $output = null): int
{ {
if (null === $output) { if (null === $output) {