From f0ab518c460a9ce4a725006a5559b4a26d742ab7 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 22 Jul 2022 10:36:27 +0200 Subject: [PATCH] Ensure signalHandler is kept around and unregistered --- src/Composer/Console/Application.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 315379a2c..fc0144bd4 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -81,6 +81,9 @@ class Application extends BaseApplication */ private $initialWorkingDirectory; + /** @var SignalHandler */ + private $signalHandler; + public function __construct() { static $shutdownRegistered = false; @@ -96,13 +99,13 @@ class Application extends BaseApplication $this->io = new NullIO(); + $this->signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) { + $this->io->writeError('Received '.$signal.', aborting', true, IOInterface::DEBUG); + + $handler->exitWithLastSignal(); + }); + if (!$shutdownRegistered) { - $signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal, SignalHandler $handler) { - $this->io->writeError('Received '.$signal.', aborting', true, IOInterface::DEBUG); - - $handler->exitWithLastSignal(); - }); - $shutdownRegistered = true; register_shutdown_function(static function (): void { @@ -121,6 +124,11 @@ class Application extends BaseApplication parent::__construct('Composer', Composer::getVersion()); } + public function __destruct() + { + $this->signalHandler->unregister(); + } + public function run(InputInterface $input = null, OutputInterface $output = null): int { if (null === $output) {