Is there a race condition when a lock is released?
See original GitHub issueConsider a situation with two processes:
- Process 1 currently holds a lock.
- Process 2 is waiting for
BLPOP
to return.
Now, suppose that the following sequence of events unfolds:
- Process 1 executes the
UNLOCK
script to release the lock. - Process 2’s
BLPOP
returns. - Before Process 2 can call
SETNX
, Process 3 callsSETNX
, thereby jumping to the front of the queue and making Process 2 very cross indeed.
Am I thinking about this correctly, or is this not actually possible?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Reading 23: Locks and Synchronization
When used properly and carefully, locks can prevent race conditions. But then another problem rears its ugly head. Because the use of locks...
Read more >Race Conditions, Locks, Semaphores, and Deadlocks - Medium
The most common type of race condition is check-then-act. ... acquire a lock held by thread B, A must wait, or block, until...
Read more >Race conditions and deadlocks - Visual Basic - Microsoft Learn
A deadlock occurs when two threads each lock a different variable at the same time and then try to lock the variable that...
Read more >What prevents a race condition on a lock?
When lock is equal to 0 another thread can enter to critical section - while loop ends. Thread suspending - for example counting...
Read more >What is a Race Condition? - TechTarget
It can be made to occur when two or more threads must wait for one another to acquire or release a lock in...
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
Maybe there’s a way using redis streams but I have to wonder if this is worth fixing.
If anyone wants to take a stab there’s the https://github.com/ionelmc/python-redis-lock/tree/race-on-unlock branch with a test for this.
Actually scratch that, llen would most always be 0 (an element is added there on unlock).
I don’t really think I can fix this …