Skip to content

Commit 031d739

Browse files
committed
fix(cron): Fix infinite loop on ParallelAware blocked jobs
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent de46e39 commit 031d739

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/private/BackgroundJob/JobList.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
use function strlen;
2525

2626
class JobList implements IJobList {
27+
/** @var array<string, int> */
28+
protected array $alreadyVisitedParallelBlocked = [];
29+
2730
public function __construct(
2831
protected IDBConnection $connection,
2932
protected IConfig $config,
@@ -198,6 +201,12 @@ public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = nu
198201
$job = $this->buildJob($row);
199202

200203
if ($job instanceof IParallelAwareJob && !$job->getAllowParallelRuns() && $this->hasReservedJob(get_class($job))) {
204+
if (!isset($this->alreadyVisitedParallelBlocked[get_class($job)])) {
205+
$this->alreadyVisitedParallelBlocked[get_class($job)] = $job->getId();
206+
} elseif ($this->alreadyVisitedParallelBlocked[get_class($job)] === $job->getId()) {
207+
$this->logger->info('Skipped through all jobs and revisited a IParallelAwareJob blocked job again, giving up.', ['app' => 'cron']);
208+
return null;
209+
}
201210
$this->logger->info('Skipping ' . get_class($job) . ' job with ID ' . $job->getId() . ' because another job with the same class is already running', ['app' => 'cron']);
202211

203212
$update = $this->connection->getQueryBuilder();
@@ -210,6 +219,10 @@ public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = nu
210219
return $this->getNext($onlyTimeSensitive, $jobClasses);
211220
}
212221

222+
if ($job !== null && isset($this->alreadyVisitedParallelBlocked[get_class($job)])) {
223+
unset($this->alreadyVisitedParallelBlocked[get_class($job)]);
224+
}
225+
213226
if ($job instanceof \OCP\BackgroundJob\TimedJob) {
214227
$now = $this->timeFactory->getTime();
215228
$nextPossibleRun = $job->getLastRun() + $job->getInterval();

0 commit comments

Comments
 (0)