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

Skip to content

Too early resetting services in messenger #43114

Closed
@upyx

Description

@upyx

Symfony version(s) affected: 5.4.x

Description
I use a new feature added in #41163 with UidProcessor from Monolog. Recently I've realized the last INFO log from the messenger ("{class} was handled successfully (acknowledging to transport)") has a uid from the following message in a queue. It happens because that log message writes after the WorkerMessageHandledEvent that triggers resetting. It sounds silly, but I've spent hours trying to understand why a wrong message has a positive acknowledgment.

How to reproduce
Register service:

services:
    Monolog\Processor\UidProcessor:
        tags: [ 'monolog.processor' ]

Configure messenger:

framework:
    messenger:
        transports:
            async:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                reset_on_message: true
        routing:
            App\Message: async

Consume some message:

bin/console messenger:consume async -vv

Example output:

19:50:03 INFO [messenger] Received message App\Message ["class" => "App\Message"] ["uid" => "4f9fa66"]
19:50:03 INFO [messenger] Message App\Message handled by App\Handler::__invoke ["class" => "App\Message","handler" => "App\Handler::__invoke"] ["uid" => "4f9fa66"]
19:50:03 INFO [messenger] App\Message was handled successfully (acknowledging to transport). ["class" => "App\Message"] ["uid" => "17280ae"]
19:50:04 INFO [messenger] Received message App\Message ["class" => "App\Message"] ["uid" => "17280ae"]
19:50:04 INFO [messenger] Message App\Message handled by App\Handler::__invoke ["class" => "App\Message","handler" => "App\Handler::__invoke"] ["uid" => "17280ae"]
19:50:04 INFO [messenger] App\Message was handled successfully (acknowledging to transport). ["class" => "App\Message"] ["uid" => "b3d9ee5"]

Possible Solution
I think the service resetting should be the last thing in a handling loop: after logging, after acknowledging. The actual event for that is WorkerRunningEvent. The event doesn't have a transport name, but it's trivial to fix. Nevertheless, I have doubts about all of this.

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