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.