Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hangfire DisableConcurrentExecution: What happens when the timeout expires?

Tags:

c#

hangfire

Per the Hangfire 0.8.2 announcement post, Hangfire has a DisableConcurrentExecution filter which, when applied to a method, prevents multiple instances of the method from executing concurrently.

The DisableConcurrentExecution filter takes a timeoutInSeconds int parameter. From the example in the linked article:

[DisableConcurrentExecution(timeoutInSeconds: 10 * 60)]
public void SomeMethod()
{
    // Operations performed inside a distributed lock
}

My question is: What happens when, given a job which is waiting on obtaining the lock for a DisableConcurrentExecution-filtered method, the time that the job has been waiting exceeds the timeoutInSeconds value?

like image 594
Jon Schneider Avatar asked Nov 09 '16 21:11

Jon Schneider


1 Answers

I tested that recently. That job instance was recorded as failed in the dashboard and listed the exception which indicated that the timeout had expired while waiting for an exclusive lock.

You'll see the following exception:

Hangfire.Storage.DistributedLockTimeoutException: Timeout expired. The timeout elapsed prior to obtaining a distributed lock on the 'xxx' resource.
    at Hangfire.SqlServer.SqlServerDistributedLock.Acquire(IDbConnection connection, String resource, TimeSpan timeout)
like image 122
Nat Wallbank Avatar answered Oct 30 '22 18:10

Nat Wallbank