You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For some reason, I occasionally can't release a stale lock. I have described my debugging process below and would like to know if anyone can suggest how to further debug.
Assume that we want to create a redis lock with this name:
name="test"
We insert this variable in two different terminal windows. In the first, we run:
deflock_for_15_secs(name)job=Redis::Semaphore.new(name.to_sym,redis: NonBlockingRedis.new(),custom_blpop: true,:stale_client_timeout=>15)ifjob.lock(-1) == "0"puts"Locked and starting"sleep(15)puts"Now it's stale, try to release in another process"sleep(15)puts"Now trying to unlock"unlock=job.unlockputsunlock == false ? "Wuhuu, already unlocked" : "Hm, should have been unlocked by another process, but wasn't"endendlock_for_15_secs(name)
In the second we run:
defrelease_and_lock(name)job=Redis::Semaphore.new(name.to_sym,redis: NonBlockingRedis.new(),custom_blpop: true,:stale_client_timeout=>15)release=job.release_stale_locks!count=job.available_countputs"Release reponse is #{release.inspect} and available count is #{count}"ifjob.lock(-1) == "0"puts"Wuhuu, we can lock it"job.unlockelseputs"Hmm, we can't lock it"endendrelease_and_lock(name)
This usually plays out as expected. For 15 seconds, the second terminal can't relase the lock, but when I run it again it releases. Below is the output from release_and_lock(name).
Before 15 seconds have passed:
irb(main):1:0> release_and_lock(name)
Release reponse is {"0"=>"1580292557.321834"} and available count is 0
Hmm, we can't lock it
=> nil
After 15 seconds have passed:
irb(main):2:0> release_and_lock(name)
Release reponse is {"0"=>"1580292557.321834"} and available count is 1
Wuhuu, we can lock it
=> 1
irb(main):3:0> release_and_lock(name)
Release reponse is {} and available count is 1
Wuhuu, we can lock it
But sometimes in production I see that a stale lock isn't released, so I try to run the release_and_lock(name) to diagnose. It returns:
irb(main):4:0> release_and_lock(name)
Release reponse is {} and available count is 0
Hmm, we can't lock it
And at this point my only option is to flush redis:
I am using gem version 0.3.1.
For some reason, I occasionally can't release a stale lock. I have described my debugging process below and would like to know if anyone can suggest how to further debug.
Assume that we want to create a redis lock with this name:
We insert this variable in two different terminal windows. In the first, we run:
In the second we run:
This usually plays out as expected. For 15 seconds, the second terminal can't relase the lock, but when I run it again it releases. Below is the output from
release_and_lock(name)
.Before 15 seconds have passed:
After 15 seconds have passed:
But sometimes in production I see that a stale lock isn't released, so I try to run the
release_and_lock(name)
to diagnose. It returns:And at this point my only option is to flush redis:
P.s. My
NonBlockingRedis
inherits fromRedis
:The text was updated successfully, but these errors were encountered: