[Messenger] Drop the messages queued by a failed nested dispatch - #66032
Merged
nicolas-grekas merged 1 commit intoSep 13, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A message dispatched with a
DispatchAfterCurrentBusStampfrom 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.
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/Testson 6.4: 425 tests, green.testMessagesQueuedByAFailedNestedDispatchAreDroppederrors without the fix, because the event queued by the failed nested dispatch reaches the handling middleware a third time.