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.

First of all, let me congratulate you for the way you handle your issues, your answers are complete and thoughtful.

Now, to my issue: I’m seeing a relatively small (1-3% out of around 100.000 tries) of LockError when trying to lock a resource. It exceeds the 10 attempts to lock.

What are the possible causes for a lock to fail? From what I could gather, I am not attempting to lock the same resource twice (there are no other calls to lock a resource with the same tag LOCK:STATUS:PAYLOAD:${id})

Is there something I could do about it? I know it’s hard without sharing any more code.

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mike-marcaccicommented, Mar 28, 2019

You’re super welcome; and glad to help! As far as open source projects are concerned, the issues that get filed here tend to be amazingly high-quality and well thought out. That makes it easy to respond with similar thoughtfulness 😃

1reaction
mike-marcaccicommented, Mar 27, 2019

Hi @bzuker - my apologies for the delay!

That’s a great question, with a couple different possible answers.

Let’s say you have redlock configured for 3 attempts instead of 10. One possibility is simply that the lock was acquired for the entire duration of your attempts. This can happen a couple different ways.

In the simplest case, one actor (A) acquires the lock and holds it for the entire time that a second actor (B) attempts to acquire a lock for the same resource:

   acquire        release
A     |              |
---------------------------
B       |    |    |
        1    2    3 

Another possibility is that if the resource is under reasonable contention, that multiple different actors hold the lock for the duration that B is attempting to acquire the lock:

  acquire   release
A     |        |
---------------------------
        |    |     |
B       1    2     3 
        |    |     |
---------------------------
C                |       |
            acquire    release

The first scenario can be solved by increasing the retryCount, or by increasing the retryDelay between attempts. However, increasing the delay would make the second scenario more likely, since it increases the opportunity for C to sneak in and acquire the lock first.

Another totally different scenario is only applicable in a high-availability setup. In this scenario, under very high contention, different actors can partially acquire locks on different redis servers, leading to a scenario where nobody fully acquires the lock, and everyone has to retry. However, if they all retry at the same time, we might simply repeat this scenario. To prevent this, it’s important that the retryJitter is high enough to avoid this kind of resonance.

At the end of the day, the most corse setting to play with is going to be retryCount: if you’d rather wait than error, turn this up (you can go as high as Infinity, also representable as -1 if your configs need to be JSON serializable); if you would rather stop the operation, though, then you can turn it down as low as 0.

Hope that helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firearm malfunction - Wikipedia
A firearm malfunction is the failure of a firearm to operate as intended for causes other than user error. Malfunctions range from temporary...
Read more >
Questions About the Failure of Mortgage Locks
What Is a Lock Failure? A lock failure occurs when a lender does not honor a mortgage price that a borrower had believed...
Read more >
Fail Safe vs Fail Secure - and what most people get wrong! - Kisi
Fail secure locks are used for fire related doors or staircase (stairwell) doors. The reason is that in case of fire, those doors...
Read more >
What is fail locked and fail unlocked? - Quora
Fail locked (also known as Fail Secure) means that if in the event of the electricity supply (whatever it may be) fails, then...
Read more >
Lock failure or bad lineshape
If the lock level is smaller than 10 after shimming, the lock may fail during the acquisition and lineshape may be bad. Lock...
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