From 105bc5616f99721572a6f11e392abeb3b0329879 Mon Sep 17 00:00:00 2001 From: Gowtham Date: Sat, 30 Dec 2023 02:42:09 +0530 Subject: [PATCH] fix(concurrency): Fix release lock for concurrency jobs For issue context, please check: https://github.com/gocraft/work/issues/192 --- dead_pool_reaper.go | 10 ++++++---- dead_pool_reaper_test.go | 5 +++-- redis.go | 4 ---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/dead_pool_reaper.go b/dead_pool_reaper.go index e930521e..171aa555 100644 --- a/dead_pool_reaper.go +++ b/dead_pool_reaper.go @@ -95,14 +95,16 @@ func (r *deadPoolReaper) reap() error { // try to clean up locks for the current set of jobs if heartbeat was not found lockJobTypes = r.curJobTypes } - // Remove dead pool from worker pools set - if _, err = conn.Do("SREM", workerPoolsKey, deadPoolID); err != nil { - return err - } + // Cleanup any stale lock info if err = r.cleanStaleLockInfo(deadPoolID, lockJobTypes); err != nil { return err } + + // Remove dead pool from worker pools set + if _, err = conn.Do("SREM", workerPoolsKey, deadPoolID); err != nil { + return err + } } return nil diff --git a/dead_pool_reaper_test.go b/dead_pool_reaper_test.go index 6c21cbc6..d89606de 100644 --- a/dead_pool_reaper_test.go +++ b/dead_pool_reaper_test.go @@ -336,9 +336,10 @@ func TestDeadPoolReaperCleanStaleLocks(t *testing.T) { // now clean lock info for workerPoolID2 reaper.cleanStaleLockInfo(workerPoolID2, jobNames) assert.NoError(t, err) - // both locks should be at 0 + + // lock should be at 0 assert.EqualValues(t, 0, getInt64(pool, lock1)) - assert.EqualValues(t, 0, getInt64(pool, lock2)) + // worker pool ID 2 removed from both lock info hashes v, err = conn.Do("HGET", lockInfo1, workerPoolID2) assert.Nil(t, v) diff --git a/redis.go b/redis.go index 417eb481..137ee84b 100644 --- a/redis.go +++ b/redis.go @@ -209,10 +209,6 @@ for i=1,keylen,2 do if deadLockCount then redis.call('decrby', lock, deadLockCount) redis.call('hdel', lockInfo, deadPoolID) - - if tonumber(redis.call('get', lock)) < 0 then - redis.call('set', lock, 0) - end end end return nil