Skip to content

Commit

Permalink
fix(concurrency): Fix release lock for concurrency jobs
Browse files Browse the repository at this point in the history
For issue context, please check: gocraft#192
  • Loading branch information
gwthm-in authored and gokul1630 committed Mar 29, 2024
1 parent 846e924 commit 105bc56
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
10 changes: 6 additions & 4 deletions dead_pool_reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions dead_pool_reaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 105bc56

Please sign in to comment.