Ensure signalHandler is kept around and unregistered
parent
4aa3258d19
commit
f0ab518c46
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue