diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php index e4831557f01db..a743a34ce6b4a 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineTransactionMiddleware.php @@ -34,7 +34,10 @@ protected function handleForManager(EntityManagerInterface $entityManager, Envel return $envelope; } catch (\Throwable $exception) { - $entityManager->getConnection()->rollBack(); + try { + $entityManager->getConnection()->rollBack(); + } catch (\Throwable $e) { + } if ($exception instanceof HandlerFailedException) { // Remove all HandledStamp from the envelope so the retry will execute all handlers again. diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php index f0eb0b22efcf4..cc2bc31624af8 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrineTransactionMiddlewareTest.php @@ -69,6 +69,22 @@ public function testTransactionIsRolledBackOnException() $this->middleware->handle(new Envelope(new \stdClass()), $this->getThrowingStackMock()); } + public function testExceptionRollingBackTransactionSwallowed() + { + $this->connection->expects($this->once()) + ->method('beginTransaction') + ; + $this->connection->expects($this->once()) + ->method('rollBack') + ->will($this->throwException(new \Exception('Could not roll back transaction.'))) + ; + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Thrown from next middleware.'); + + $this->middleware->handle(new Envelope(new \stdClass()), $this->getThrowingStackMock()); + } + public function testInvalidEntityManagerThrowsException() { $managerRegistry = $this->createMock(ManagerRegistry::class);