8000 Behavior changed with messenger:consume and signals · Issue #52077 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Behavior changed with messenger:consume and signals #52077

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
hlecorche opened this issue Oct 16, 2023 · 2 comments
Closed

Behavior changed with messenger:consume and signals #52077

hlecorche opened this issue Oct 16, 2023 · 2 comments

Comments

@hlecorche
Copy link
Contributor

Symfony version(s) affected

6.3.5 and 6.3-dev

Description

Since version 6.3.5, there is a compatibility break with the messenger:consume command and signals.

  • After : If SIGINT or SIGTERM signals were sent, the worker stopped AFTER processing the current message
  • Now (6.3.5 and 6.3-dev) : If SIGINT or SIGTERM signals are sent, the worker stops immediately even if a message is being processed (hard stop)

Here are some issues with this change :

  • If Supervisor is used, the supervisorctl stop xxx command can stop the worker before the processing of the current message is completed (hard stop).
  • I'm using the Symfony\Component\Messenger\Event\WorkerMessageFailedEvent event to catch an error. If an error is encountered, the listener stops the task group with Supervisor (with its API and SIGTERM) and sends an email. Now when the event calls the Supervisor API to stop, all actions performed after its call are no longer performed:
    • The email is no longer sent
    • Retry strategy does not work
    • Message processing was stopped abruptly

Link with #50787 ?

How to reproduce

Repository :

Commands :

  • Execute the command php bin/console doctrine:database:create && php bin/console doctrine:schema:update --force
  • Execute the command php bin/console app:create-message && php bin/console messenger:consume async -vvv
  • Send SIGTERM signal

After (< 6.3.5) :

php bin/console  app:create-message && php bin/console messenger:consume async -vvv

                                                                                                                        
 [OK] Consuming messages from transport "async".                                                                        
                                                                                                                        

 // The worker will automatically exit once it has received a stop signal via the messenger:stop-workers command.       

 // Quit the worker with CONTROL-C.                                                                                     

[info] Received message App\Messenger\Message\MessageSuccess
[info] Received signal 15.
[info] Stopping worker.
^ "The worker will stop correctly"
[info] Message App\Messenger\Message\MessageSuccess handled by App\Messenger\MessageHandler\MessageSuccessHandler::__invoke
[info] App\Messenger\Message\MessageSuccess was handled successfully (acknowledging to transport).

Now (6.3.5 and 6.3-dev) :


php bin/console  app:create-message && php bin/console messenger:consume async -vvv

                                                                                                                        
 [OK] Consuming messages from transport "async".                                                                        
                                                                                                                        

 // The worker will automatically exit once it has received a stop signal via the messenger:stop-workers command.       

 // Quit the worker with CONTROL-C.                                                                                     

[info] Received message App\Messenger\Message\MessageSuccess
[info] Received signal 15.
[info] Stopping worker.

Possible Solution

No response

Additional Context

When I did my tests, pcntl was enabled (echo \SIGINT; returns 2)

@HypeMC
Copy link
Member
HypeMC commented Oct 16, 2023

@hlecorche Hi, could you please check if #52080 fixes the issue.

@hlecorche
Copy link
Contributor Author

Hi @HypeMC ,

It works.

Thank you very much for your work ! 🙂👍

fabpot added a commit that referenced this issue Oct 16, 2023
This PR was merged into the 6.3 branch.

Discussion
----------

[Messenger] Fix graceful exit

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #52077
| License       | MIT

My previous PR #50787 accidentally broke the behavior of the `messenger:consume` command. It no longer waits for the handler to finish, instead it exists immediately.

Commits
-------

b270382 [Messenger] Fix graceful exit
@fabpot fabpot closed this as completed Oct 16, 2023
hlecorche added a commit to hlecorche/messenger-supervisor-bundle that referenced this issue Oct 17, 2023
hlecorche added a commit to hlecorche/messenger-supervisor-bundle that referenced this issue Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0