Managing the same lock with different handlers
See original GitHub issueDescribe the bug Sometimes I need to acquire and release the same lock with different objects. I am constricted by a legacy design to do it this way, because acquiring and releasing the lock will be in separate processes. However, if I open a second handle to the same lock key, I can’t release the lock from there.
To Reproduce
Python 3.6.5 (default, Mar 25 2020, 10:32:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pottery
>>> import redis
>>> lock = pottery.Redlock(key="test-lock", masters={redis.Redis()}, auto_release_time=40000)
>>> lock.acquire()
True
>>> lock.locked()
33200
>>> lock2 = pottery.Redlock(key="test-lock", masters={redis.Redis()}, auto_release_time=40000)
>>> lock.locked()
23395
>>> lock2.locked()
0
>>> lock2.release()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/arieroos/Workspace/dos/venv/lib/python3.6/site-packages/pottery/redlock.py", line 572, in release
redis_errors=redis_errors,
pottery.exceptions.ReleaseUnlockedLock: key='redlock:test-lock', masters=[Redis<ConnectionPool<Connection<host=localhost,port=6379,db=0>>>], redis_errors=[]
Expected behavior
Python 3.6.5 (default, Mar 25 2020, 10:32:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pottery
>>> import redis
>>> lock = pottery.Redlock(key="test-lock", masters={redis.Redis()}, auto_release_time=40000)
>>> lock.acquire()
True
>>> lock.locked()
33200
>>> lock2 = pottery.Redlock(key="test-lock", masters={redis.Redis()}, auto_release_time=40000)
>>> lock.locked()
23395
>>> lock2.locked()
13395 # or some integer like that
>>> lock2.release()
# no exception thrown
Environment (please complete the following information):
- OS: macOS (However, I use Linux in production)
- Python version: 3.5.6
Additional context Currently I just ignore the Exception, as most locks will expire in time anyway. However, that is probably bad practice.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:7
Top Results From Across the Web
Alternatives To Using The Same Key For All Locks
Managing keys for multiple locks has never been so easy. If you're looking for a better alternative to: Carrying a bulky ring of...
Read more >Lock User Management (LUM) FAQ's and Tips
Yes you can control multiple locks from a single app instance. Select all locks on the main page and then you can assign...
Read more >Lock handler for arbitrary keys - java - Stack Overflow
The crudest way to do this is to associate every key with the same lock, which results in the coarsest synchronization possible. On...
Read more >Transaction locking and row versioning guide - SQL Server
Each transaction requests locks of different types on the resources, ... the same row several times and reads different data each time.
Read more >Lock Handling
From a usage point of view, the BDB SQL interface behaves in the same way as ... It also has a locking model...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same issue here - you’d expect a distributed lock - to be distributed; if you can’t check if a lock is locked from a different resource then there isn’t much use.
It’s weird, I got same error by below code.
Error Info: