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

Unsafe distributed lock with Redis #19

Open
Jack12816 opened this issue Feb 16, 2022 · 0 comments
Open

Unsafe distributed lock with Redis #19

Jack12816 opened this issue Feb 16, 2022 · 0 comments

Comments

@Jack12816
Copy link

Hey guys,

I stumbled upon this gem while working on an updated test suite for activejob-locking. When I was using the Redis client/implementation my tests for parallel lock acquisition failed, so the lock was over-acquired. (Eg. 3 time parallel processes, on the same machine or on different machines, could acquire the same lock, each)

See: https://bit.ly/3LAT9cl

The issue is based on the Redis watch command in case there is no such key in the first place. To work around this a user must make sure to set the key (to an empty string) before any process wants to acquire the lock. This can be done at application boot or while deployments.

I set up a demo repository for reproducibility: https://github.com/Jack12816/suo-dlm-redis-bug

The Memcached client/implementation does not suffer from this issue as far as I can tell.


See Redlock for a canonical Redis DLM algorithm as an alternative, in case you care about the safety guarantee that at any given moment, only one client can hold a lock.


Proposal: Maybe we could add a hint about this in the readme?

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