Skip to content

Commit e76485d

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

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/private/BackgroundJob/JobList.php

Lines changed: 9 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();

0 commit comments

Comments
 (0)