From a4ee8a08b7b39bb3eb80add87fff1d694bb928e5 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Tue, 6 Feb 2024 14:30:03 +0100 Subject: [PATCH] [Messenger] Rollback if possible --- .../Doctrine/Messenger/DoctrineTransactionMiddleware.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php index e4831557f01db..e5bee1dc8136e 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php @@ -34,7 +34,9 @@ protected function handleForManager(EntityManagerInterface $entityManager, Envel return $envelope; } catch (\Throwable $exception) { - $entityManager->getConnection()->rollBack(); + if ($entityManager->getConnection()->isTransactionActive()) { + $entityManager->getConnection()->rollBack(); + } if ($exception instanceof HandlerFailedException) { // Remove all HandledStamp from the envelope so the retry will execute all handlers again.