Skip to content

Commit 9cc7d8f

Browse files
committed
Decrease LockTimeout time for sp_getapplock
This will cause slightly more queries, but will keep less worker threads in SQL Server blocked when attempting to acquire an already taken distributed lock.
1 parent 02bd907 commit 9cc7d8f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: src/Hangfire.SqlServer/SqlServerDistributedLock.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Hangfire.SqlServer
2828
{
2929
public class SqlServerDistributedLock : IDisposable
3030
{
31-
private static readonly TimeSpan LockTimeout = TimeSpan.FromSeconds(5);
31+
private static readonly TimeSpan LockTimeout = TimeSpan.FromSeconds(1);
3232

3333
private const string LockMode = "Exclusive";
3434
private const string LockOwner = "Session";
@@ -191,7 +191,7 @@ internal static void Acquire(DbConnection connection, string resource, TimeSpan
191191

192192
do
193193
{
194-
var command = connection
194+
using var command = connection
195195
.Create("sp_getapplock", CommandType.StoredProcedure, timeout: (int)(lockTimeout / 1000) + 5)
196196
.AddParameter("@Resource", resource, DbType.String, size: 255)
197197
.AddParameter("@DbPrincipal", "public", DbType.String, size: 32)

0 commit comments

Comments
 (0)