Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Also listen to SIGINT in StopWorkerOnSigtermSignalListener #49156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lyrixx opened this issue Jan 30, 2023 · 5 comments · Fixed by #49539
Closed

[Messenger] Also listen to SIGINT in StopWorkerOnSigtermSignalListener #49156

lyrixx opened this issue Jan 30, 2023 · 5 comments · Fixed by #49539
Labels
Messenger RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@lyrixx
Copy link
Member

lyrixx commented Jan 30, 2023

Description

ATM, StopWorkerOnSigtermSignalListener listen only SIGTERM.

IMHO, it should also listen SIGINT (CTR+C) for the following reasons:

  • in dev, we can have the same behavior than in production
  • in prod, when adding manually more consumers (yeah, SSH + bin/console 🧓🏼), it's boring to stop them cleanly. CTRL+C is easier
  • I always found it weird it doesn't listen SIGINT - Okay, this is not a valid argument :)

cc @Tobion


I'll make the PR if accepted

@lyrixx lyrixx added the RFC RFC = Request For Comments (proposals about features that you want to be discussed) label Jan 30, 2023
@OskarStark OskarStark changed the title [Messenger] Also listen SIGINT in StopWorkerOnSigtermSignalListener [Messenger] Also listen to SIGINT in StopWorkerOnSigtermSignalListener Feb 3, 2023
@rmikalkenas
Copy link
Contributor

rmikalkenas commented Feb 21, 2023

What if make possible sygnals configurable via constructor? It could accept an array of posix signals which would stop the worker.

For example in my project, we terminate workers with SIGQUIT and for it to work I had to create a new listener

@lyrixx wdyt?

@lyrixx
Copy link
Member Author

lyrixx commented Feb 22, 2023

How Would you configure the subscriber ?

@rmikalkenas
Copy link
Contributor

@lyrixx like this. Except $signal could be int[] instead, then onWorkerStarted would simply iterate and call pcntl_signal

final class StopWorkerOnPcntlSignalListener implements EventSubscriberInterface
{
    public function __construct(private readonly int $signal) {}

    public static function getSubscribedEvents(): array
    {
        return [WorkerStartedEvent::class => ['onWorkerStarted', 100]];
    }

    public function onWorkerStarted(WorkerStartedEvent $event): void
    {
        pcntl_signal(
            $this->signal,
            static function () use ($event): void {
                $event->getWorker()->stop();
            },
        );
    }
}

@lyrixx
Copy link
Member Author

lyrixx commented Feb 23, 2023

Sorry, I was not clear. With Symfony full stack, this service is not created by you, but by the framework. So how would you configure it? I think we can set some sane defaults, then if you want other signals, you replace the services arguments. Are you OK with this? I'll do the PR ASAP

@lyrixx
Copy link
Member Author

lyrixx commented Feb 26, 2023

I opened a PR ☝

@fabpot fabpot closed this as completed in 550b92f Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Messenger RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants