Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hangfire.LiteDB get locked for concurrent access #23

Open
vpatil007 opened this issue Jan 2, 2020 · 4 comments
Open

Hangfire.LiteDB get locked for concurrent access #23

vpatil007 opened this issue Jan 2, 2020 · 4 comments

Comments

@vpatil007
Copy link

We are having problems with accessing the LiteDB database with Hangfire implementation. We are using Hangfire.LiteDB (0.3.0) and looks like for concurrent multi process environment database is getting locked, which results in crashing the Hangfire jobs. The size of the database is really small (3MB).

We are simply creating the connection and attaching it to the hangfireDB. Following is the connection code,

`public void ConfigureServices(IServiceCollection service)
{
ApiStartupExtensions.ConfigureServices(Configuration, service, _currentHostingEnvironment);

        ApplicationContext context = new ApplicationContext()
        {
            ApplicationConfiguration = Configuration,
        };
        //Register RetryPolicies as Singelton
        service.AddSingleton<RetryPolicies>();
        service.AddHangfire(t => t.UseLiteDbStorage(Configuration.GetConnectionString("HangfireConnection")));            
    }`

Could you share an example of how to implement concurrency with Hangfire jobs using HangFire.LiteDB or You can suggest a necessary changes required?

@vpatil007 vpatil007 changed the title Concurrency Implementation with Hangfire.LiteDB Hangfire.LiteDB get locked for concurrent access Jan 2, 2020
@felixclase
Copy link
Contributor

Try 0.3.1 version...

@hxbb00
Copy link

hxbb00 commented Oct 29, 2020

Execution RecurringJobScheduler is in the Failed state now due to an exception, execution will be retried no more than in 00:00:04 Hangfire.Storage.DistributedLockTimeoutException: Timeout expired. The timeout elapsed prior to obtaining a distributed lock on the 'Could not place a lock on the resource 'HangFire:recurring-jobs:lock': The lock request timed out.' resource. at Hangfire.LiteDB.LiteDbDistributedLock.Acquire(TimeSpan timeout) at Hangfire.LiteDB.LiteDbDistributedLock..ctor(String resource, TimeSpan timeout, HangfireDbContext database, LiteDbStorageOptions storageOptions) at Hangfire.LiteDB.LiteDbConnection.AcquireDistributedLock(String resource, TimeSpan timeout) at Hangfire.Server.RecurringJobScheduler.UseConnectionDistributedLock[T](JobStorage storage, Func2 action)
at Hangfire.Server.RecurringJobScheduler.EnqueueNextRecurringJobs(BackgroundProcessContext context)
at Hangfire.Server.RecurringJobScheduler.Execute(BackgroundProcessContext context)
at Hangfire.Server.BackgroundProcessDispatcherBuilder.ExecuteProcess(Guid executionId, Object state)
at Hangfire.Processing.BackgroundExecution.Run(Action2 callback, Object state)

i meet this exception too

@majora2007
Copy link

I get this all the time, I was never able to solve (I'm on 0.4.0 with .NET 5) and switched to MemoryStorage

@mrsquish
Copy link

mrsquish commented Mar 18, 2024

Yep, me too. Brand new app .Net8, still in development. Couldn't work out why the scheduled jobs wouldn't trigger. Then got the same exception as above.

Hangfire.Processing.BackgroundExecution: Error: Execution RecurringJobScheduler is in the Failed state now due to an exception, execution will be retried no more than in 00:00:04

Hangfire.Storage.DistributedLockTimeoutException: Timeout expired. The timeout elapsed prior to obtaining a distributed lock on the 'Could not place a lock on the resource 'HangFire:recurring-jobs:lock': The lock request timed out.' resource.
   at Hangfire.LiteDB.LiteDbDistributedLock.Acquire(TimeSpan timeout)
   at Hangfire.LiteDB.LiteDbDistributedLock..ctor(String resource, TimeSpan timeout, HangfireDbContext database, LiteDbStorageOptions storageOptions)
   at Hangfire.LiteDB.LiteDbConnection.AcquireDistributedLock(String resource, TimeSpan timeout)
   at Hangfire.Server.RecurringJobScheduler.UseConnectionDistributedLock[T](JobStorage storage, Func`2 action) in C:\projects\hangfire-525\src\Hangfire.Core\Server\RecurringJobScheduler.cs:line 389
   at Hangfire.Server.RecurringJobScheduler.EnqueueNextRecurringJobs(BackgroundProcessContext context) in C:\projects\hangfire-525\src\Hangfire.Core\Server\RecurringJobScheduler.cs:line 186
   at Hangfire.Server.RecurringJobScheduler.Execute(BackgroundProcessContext context) in C:\projects\hangfire-525\src\Hangfire.Core\Server\RecurringJobScheduler.cs:line 159
   at Hangfire.Server.BackgroundProcessDispatcherBuilder.ExecuteProcess(Guid executionId, Object state) in C:\projects\hangfire-525\src\Hangfire.Core\Server\BackgroundProcessDispatcherBuilder.cs:line 82
   at Hangfire.Processing.BackgroundExecution.Run(Action`2 callback, Object state) in C:\projects\hangfire-525\src\Hangfire.Core\Processing\BackgroundExecution.cs:line 118

It would seem that LiteDB is just not fit for purpose here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants