From 87f9768b2edac095cba6fcc21ea320ef2d56cde4 Mon Sep 17 00:00:00 2001 From: Aris Tzoumas Date: Wed, 19 Oct 2022 08:58:27 +0300 Subject: [PATCH] fix(jobsdb): race - repeat job count calculation after acquiring migration lock (#2583) --- jobsdb/jobsdb.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jobsdb/jobsdb.go b/jobsdb/jobsdb.go index 7a5cdac040..f2602e8260 100644 --- a/jobsdb/jobsdb.go +++ b/jobsdb/jobsdb.go @@ -3090,6 +3090,11 @@ func (jd *HandleT) doMigrateDS(ctx context.Context) error { return fmt.Errorf("failed to acquire lock: %w", ctx.Err()) } defer jd.dsMigrationLock.Unlock() + // repeat the check after the dsMigrationLock is acquired to get correct pending jobs count. + // the pending jobs count cannot change after the dsMigrationLock is acquired + if migrateFrom, pendingJobsCount, insertBeforeDS = jd.getMigrationList(dsList); len(migrateFrom) == 0 { + return nil + } if pendingJobsCount > 0 { // migrate incomplete jobs var destination dataSetT