From a3c39360b881cf4ad83b1ad3dd98cc33fd8b77b9 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 16 Jul 2026 12:46:16 +0200 Subject: [PATCH] feat(Dispatcher): Warn about open transaction after controller method was executed Signed-off-by: provokateurin --- lib/private/AppFramework/Http/Dispatcher.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/private/AppFramework/Http/Dispatcher.php b/lib/private/AppFramework/Http/Dispatcher.php index f905296f95d38..2fa6bd8f1cbea 100644 --- a/lib/private/AppFramework/Http/Dispatcher.php +++ b/lib/private/AppFramework/Http/Dispatcher.php @@ -13,6 +13,7 @@ use OC\AppFramework\Middleware\MiddlewareDispatcher; use OC\AppFramework\Utility\ControllerMethodReflector; use OC\DB\ConnectionAdapter; +use OCP\App\IAppManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\ParameterOutOfRangeException; @@ -20,6 +21,7 @@ use OCP\Diagnostics\IEventLogger; use OCP\IConfig; use OCP\IRequest; +use OCP\Server; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; @@ -77,6 +79,12 @@ public function dispatch(Controller $controller, string $methodName): array { $response = $this->executeController($controller, $methodName); + if ($this->connection->inTransaction()) { + $this->connection->rollBack(); + $message = 'Controller method left a transaction open after executing controller method ' . $controller::class . '::' . $methodName . '. The transaction was rolled back.'; + $this->logger->warning($message, ['app' => Server::get(IAppManager::class)->getAppFromNamespace($controller::class)]); + } + if (!empty($databaseStatsBefore)) { $databaseStatsAfter = $this->connection->getInner()->getStats(); $numBuilt = $databaseStatsAfter['built'] - $databaseStatsBefore['built'];