question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a race condition when a lock is released?

See original GitHub issue

Consider 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:

  1. Process 1 executes the UNLOCK script to release the lock.
  2. Process 2’s BLPOP returns.
  3. Before Process 2 can call SETNX, Process 3 calls SETNX, 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:open
  • Created 6 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ionelmccommented, Sep 9, 2018

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.

1reaction
ionelmccommented, Sep 8, 2018

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 …

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found