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

Skip to content

[Messenger] Drop the messages queued by a failed nested dispatch - #66032

Merged
nicolas-grekas merged 1 commit into
symfony:6.4from
nicolas-grekas:messenger-nested-dispatch-queue
Sep 13, 2026
Merged

[Messenger] Drop the messages queued by a failed nested dispatch#66032
nicolas-grekas merged 1 commit into
symfony:6.4from
nicolas-grekas:messenger-nested-dispatch-queue

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Member
Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

A message dispatched with a DispatchAfterCurrentBusStamp from inside a handler is queued and dispatched once the root dispatch is over. When the nested dispatch that queued it fails, the queued messages are dispatched anyway, although the work that queued them never completed.

The root dispatch already drops its queue when handling throws, with the reasoning that the queued messages were likely dependent on the work that queued them. The nested path did not, so the two halves of the same middleware disagreed.

public function __invoke(RegisterUser $command): void
{
    try {
        // this dispatch queues UserRegistered, then throws
        $this->bus->dispatch(new CreateProfile($command->getUuid()));
    } catch (\Throwable) {
        // the caller decides to carry on
    }

    // UserRegistered was dispatched anyway, for a profile that was never created
}

Found while working on #65902, which turns each attempt of a synchronous retry into a nested dispatch and therefore meets this on every failed attempt. It is a bug of its own, so it is proposed here separately for the lowest maintained branch.

Checks

  • ./phpunit src/Symfony/Component/Messenger/Tests on 6.4: 425 tests, green.
  • testMessagesQueuedByAFailedNestedDispatchAreDropped errors without the fix, because the event queued by the failed nested dispatch reaches the handling middleware a third time.

A message dispatched with a DispatchAfterCurrentBusStamp from inside a
handler is queued and dispatched once the root dispatch is over. When the
nested dispatch that queued it failed, the queued messages were dispatched
anyway, although the work that queued them never completed. The root
dispatch already drops its queue in that case, the nested one now does the
same.
@carsonbot carsonbot added this to the 6.4 milestone Sep 13, 2026
@nicolas-grekas
nicolas-grekas merged commit f07a173 into symfony:6.4 Sep 13, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants