From 4a5e3a86318f1f6eb727466de7418b7c5b0c16dd Mon Sep 17 00:00:00 2001 From: Benjamin Gaussorgues Date: Tue, 7 Jul 2026 16:03:56 +0200 Subject: [PATCH] fix(jobs): compute memory usage after clean-up Signed-off-by: Benjamin Gaussorgues --- core/Service/CronService.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/core/Service/CronService.php b/core/Service/CronService.php index 72f359e79bdc7..f3394257dc019 100644 --- a/core/Service/CronService.php +++ b/core/Service/CronService.php @@ -226,21 +226,33 @@ private function runCli(string $appMode, ?array $jobClasses): void { ['app' => 'cron'] ); } - - if ($memoryIncrease > 50 * 1024 * 1024) { - $message = 'Memory leak detected after executing job ' . $jobDetails . '. Memory usage grew by ' . Util::humanFileSize($memoryIncrease) . '.'; + if ($jobMemoryPeak > (300 * 1024 * 1024)) { + $message + = 'Cron job used more than 300 MiB of RAM after executing job ' + . $jobDetails + . ': ' + . Util::humanFileSize($jobMemoryPeak) + . ')'; $this->logger->warning($message, ['app' => 'cron']); $this->verboseOutput($message); } - if ($jobMemoryPeak > 300 * 1024 * 1024) { - $message = 'Cron job used more than 300 MiB of RAM after executing job ' . $jobDetails . ': ' . Util::humanFileSize($jobMemoryPeak) . ')'; + + // Clean-up + $this->setupManager->tearDown(); + $this->tempManager->clean(); + + if ($memoryIncrease > (50 * 1024 * 1024)) { + $message + = 'Memory leak detected after executing job ' + . $jobDetails + . '. Memory usage grew by ' + . Util::humanFileSize($memoryIncrease) + . '.'; $this->logger->warning($message, ['app' => 'cron']); $this->verboseOutput($message); } - // clean up after unclean jobs - $this->setupManager->tearDown(); - $this->tempManager->clean(); + // Check forgotten transaction if ($this->connection->inTransaction()) { $this->connection->rollBack(); $message = 'Cron job left a transaction opened after executing job ' . $jobDetails . '. The transaction was rolled back.';