Skip to content

Commit

Permalink
Ensure signalHandler is kept around and unregistered
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek authored and emahorvat52 committed Jan 18, 2023
1 parent f805a7b commit 04c41c2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Composer/Console/Application.php
Expand Up @@ -81,6 +81,9 @@ class Application extends BaseApplication
*/
private $initialWorkingDirectory;

/** @var SignalHandler */
private $signalHandler;

public function __construct()
{
static $shutdownRegistered = false;
Expand All @@ -96,13 +99,13 @@ public function __construct()

$this->io = new NullIO();

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);
$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();
});
$handler->exitWithLastSignal();
});

if (!$shutdownRegistered) {
$shutdownRegistered = true;

register_shutdown_function(static function (): void {
Expand All @@ -121,6 +124,11 @@ public function __construct()
parent::__construct('Composer', Composer::getVersion());
}

public function __destruct()
{
$this->signalHandler->unregister();
}

public function run(InputInterface $input = null, OutputInterface $output = null): int
{
if (null === $output) {
Expand Down

0 comments on commit 04c41c2

Please sign in to comment.