lib/sidekiq/limit_fetch/global/selector.rb in sidekiq-limit_fetch-3.0.1 vs lib/sidekiq/limit_fetch/global/selector.rb in sidekiq-limit_fetch-3.1.0
- old
+ new
@@ -1,9 +1,11 @@
module Sidekiq::LimitFetch::Global
module Selector
extend self
+ MUTEX_FOR_UUID = Mutex.new
+
def acquire(queues, namespace)
redis_eval :acquire, [namespace, uuid, queues]
end
def release(queues, namespace)
@@ -13,12 +15,10 @@
def uuid
# - if we'll remove "@uuid ||=" from inside of mutex
# then @uuid can be overwritten
# - if we'll remove "@uuid ||=" from outside of mutex
# then each read will lead to mutex
- @uuid ||= Thread.exclusive do
- @uuid || SecureRandom.uuid
- end
+ @uuid ||= MUTEX_FOR_UUID.synchronize { @uuid || SecureRandom.uuid }
end
private
def redis_eval(script_name, args)