Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b68a6b3

Browse filesBrowse files
committed
bug #32154 [Messenger] fix retrying handlers using DoctrineTransactionMiddleware (Tobion)
This PR was merged into the 4.3 branch. Discussion ---------- [Messenger] fix retrying handlers using DoctrineTransactionMiddleware | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | | License | MIT | Doc PR | The retry logic only executes handlers that didn't fail using the HandledStamp. But in case of using the DoctrineTransactionMiddleware using several handlers, we need to remove the HandledStamp because those handlers got rolled back again. Commits ------- 66c2e84 [Messenger] fix retrying handlers using DoctrineTransactionMiddleware
2 parents 4e6951b + 66c2e84 commit b68a6b3
Copy full SHA for b68a6b3

File tree

1 file changed

+8
-0
lines changed
Filter options

1 file changed

+8
-0
lines changed

‎src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
use Doctrine\Common\Persistence\ManagerRegistry;
1515
use Symfony\Component\Messenger\Envelope;
16+
use Symfony\Component\Messenger\Exception\HandlerFailedException;
1617
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
1718
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
1819
use Symfony\Component\Messenger\Middleware\StackInterface;
20+
use Symfony\Component\Messenger\Stamp\HandledStamp;
1921

2022
/**
2123
* Wraps all handlers in a single doctrine transaction.
@@ -56,6 +58,12 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
5658
} catch (\Throwable $exception) {
5759
$entityManager->getConnection()->rollBack();
5860

61+
if ($exception instanceof HandlerFailedException) {
62+
// Remove all HandledStamp from the envelope so the retry will execute all handlers again.
63+
// When a handler fails, the queries of allegedly successful previous handlers just got rolled back.
64+
throw new HandlerFailedException($exception->getEnvelope()->withoutAll(HandledStamp::class), $exception->getNestedExceptions());
65+
}
66+
5967
throw $exception;
6068
}
6169
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.