diff options
author | Joas Schilling <coding@schilljs.com> | 2025-07-24 00:47:37 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2025-07-28 08:29:07 +0200 |
commit | 57651bba13fcd3768262d679f847ae18b49ab6e2 (patch) | |
tree | e835de40c527f0dba6025bf622ef9e144abdc314 | |
parent | d7f7b6c89d3aeb5faafb3e5fcbf9f0dad3916fd6 (diff) | |
download | nextcloud-server-backport/54068/stable30.tar.gz nextcloud-server-backport/54068/stable30.zip |
fix(cron): Fix infinite loop on ParallelAware blocked jobsbackport/54068/stable30
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index ddacba67fcc..b1fe620ecb3 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -23,6 +23,9 @@ use function json_encode; use function strlen; class JobList implements IJobList { + /** @var array<string, int> */ + protected array $alreadyVisitedParallelBlocked = []; + public function __construct( protected IDBConnection $connection, protected IConfig $config, @@ -197,6 +200,12 @@ class JobList implements IJobList { $job = $this->buildJob($row); if ($job instanceof IParallelAwareJob && !$job->getAllowParallelRuns() && $this->hasReservedJob(get_class($job))) { + if (!isset($this->alreadyVisitedParallelBlocked[get_class($job)])) { + $this->alreadyVisitedParallelBlocked[get_class($job)] = $job->getId(); + } elseif ($this->alreadyVisitedParallelBlocked[get_class($job)] === $job->getId()) { + $this->logger->info('Skipped through all jobs and revisited a IParallelAwareJob blocked job again, giving up.', ['app' => 'cron']); + return null; + } $this->logger->info('Skipping ' . get_class($job) . ' job with ID ' . $job->getId() . ' because another job with the same class is already running', ['app' => 'cron']); $update = $this->connection->getQueryBuilder(); @@ -209,6 +218,10 @@ class JobList implements IJobList { return $this->getNext($onlyTimeSensitive, $jobClasses); } + if ($job !== null && isset($this->alreadyVisitedParallelBlocked[get_class($job)])) { + unset($this->alreadyVisitedParallelBlocked[get_class($job)]); + } + $update = $this->connection->getQueryBuilder(); $update->update('jobs') ->set('reserved_at', $update->createNamedParameter($this->timeFactory->getTime())) |