Skip to content

Commit 41ee01c

Browse files
committed
Avoid race-condition when scheduling throttled jobs
When a job was throttled and the queue of pending jobs was fully drained between the throttle? decision and the delay calculation, the retry code would fail with "NoMethodError undefined method `last' for nil:NilClass"
1 parent 1a0870b commit 41ee01c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/sidekiq/throttled/strategy/concurrency.rb

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def retry_in(_jid, *job_args)
5858
return 0.0 if !job_limit || count(*job_args) < job_limit
5959

6060
oldest_jid_with_score = Sidekiq.redis { |redis| redis.zrange(key(job_args), 0, 0, withscores: true) }.first
61+
return 0.0 unless oldest_jid_with_score
62+
6163
expiry_time = oldest_jid_with_score.last.to_f
6264
expiry_time - Time.now.to_f
6365
end

0 commit comments

Comments
 (0)