Skip to content

Unsafe distributed lock with Redis #19

@Jack12816

Description

@Jack12816

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions