Skip to content

SignalRegistry should deregister handlers after command termination #61388

@klkvsk

Description

@klkvsk

Symfony version(s) affected

latest

Description

  1. It does not make sense to dispatch a ConsoleSignalEvent after there was a ConsoleTerminateEvent.
  2. In case if command ran multiple times, multiple Signal events will be dispatched to the same command.

How to reproduce

Using Scheduler component, as it utilizes RunCommandMessage to subsequently run other commands.

#[AsCommand('app:test:signal')]
#[AsPeriodicTask('1 seconds')]
class SignalTestCommand extends Command implements SignalableCommandInterface
{
    protected int $runCount = 0;

    public function getSubscribedSignals(): array
    {
        return [ \SIGINT ];
    }

    public function handleSignal(int $signal, false|int $previousExitCode = 0): int|false
    {
        printf("Got signal: %d\n", $signal);
        return false;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        printf("Press Ctrl-C and you will see %d signal events\n", ++$this->runCount);
        return self::SUCCESS;
    }
}
$ bin/console mes:consume -q scheduler_default
Press Ctrl-C and you will see 1 signal events
Press Ctrl-C and you will see 2 signal events
Press Ctrl-C and you will see 3 signal events
Press Ctrl-C and you will see 4 signal events
^CGot signal: 2
Got signal: 2
Got signal: 2
Got signal: 2

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions