Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using an ActiveSupport::Duration for timeouts results in indefinite block #56

Open
GuyPaddock opened this issue Sep 15, 2018 · 0 comments

Comments

@GuyPaddock
Copy link

GuyPaddock commented Sep 15, 2018

This issue is related to redis/redis-rb#782.

It appears that trying to use Rails convenience methods on Numeric for seconds, minutes, etc, when passing a timeout into lock will end up with no timeout at all.

For example, something like this will block indefinitely until the lock is released:

my_lock.lock(2.seconds) do
  # work
end

This is because the Redis gem does a switch on the exact class of the last argument to the underlying _bpop method when determining if the timeout argument is present. An ActiveSupport::Duration object pretends to be an Integer/quacks like an Integer for most situations, but does not pass this strict type check.

Based on my findings, it appears that Redis Semaphore could workaround/avoid this issue by passing the timeout as a named argument into blpop, instead of passing it as a positional argument.

@GuyPaddock GuyPaddock changed the title Using an ActiveSupport::Duration for Timeouts blocks indefinitely Using an ActiveSupport::Duration for timeouts results in indefinite block Sep 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant