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.

SqlDistributedLock timeout issue?

See original GitHub issue

Hi there.

Thank you for creating a cool library! Good code too…

I use it in my web app with sql azure to make sure that certain long running operations can only be run once at a time. It’s been working fine but I just had a weird case and I thought maybe you may know something about it.

I have a block like this:

using (var @lock = new SqlDistributedLock("hello", connectionString).TryAcquire())
 {
         if (@lock == null)
               return;

         await doLongRunningOperationAsync()
}

doLongRunningOperationAsync can take quite a long time and I had a case in production where 2 requests managed to both acquire the exclusive lock! The second one acquired the lock about 45 minutes after the first one had acquired the lock (it can take over an hour for this operation to complete…)

I use version 1.1.0.0 and as I understand it, when providing a connection string, an new connection and transaction will be created and the transaction will be the owner of the lock.

So it got me thinking. Maybe transactions have a timeout after which they are automatically closed? Maybe even the connection? In particular, sql azure can suffer transient issues and it is always a best practice to retry operations since they may fail because of temporary internal azure stuff.

So long story short, is it ok to use the SqlDistributedLock for long running operations???

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
madelsoncommented, Mar 12, 2017

@clement911 I’ve released a new 1.3 version containing a keepalive implementation. This can be used by passing in the Azure connection strategy when constructing the lock. Let me know how it works!

For the connection monitoring API, I’ve created a separate issue to track (https://github.com/madelson/DistributedLock/issues/6).

0reactions
madelsoncommented, Apr 1, 2017

Glad it’s working and thanks for letting me know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL distributed lock not releasing on dispose
The thing is I always get timeout after first lock acquiring, as if it never gets released. While it is said that lock...
Read more >
Timeout expired messages when connecting to SQL Server
A timeout error means that a certain operation takes longer than needed. The client application stops the operation (instead of waiting ...
Read more >
How to do distributed locking
But timeouts do not have to be accurate: just because a request times out, that doesn't mean that the other node is definitely...
Read more >
DistributedLock.Core 1.0.3
timeout determines how long Acquire will wait before failing with a TimeoutException and how long TryAcquire will wait before returning null.
Read more >
Distributed Locking via SQL Server
Regardless of what else happens, the lock server will drop the lock after 5 minutes; the maximum duration specified in the get 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