Hangfire.Mongo: Hangfire.Mongo.DistributedLock.MongoDistributedLockException: Could not release a lock on the resource 'HangFire:locks:schedulepoller'

Hi, I got this error using Hangfire.Mongo drive.

Environment:

  • Win. Server 2012;
  • 3 nodes of MongoDB with replication set;
  • Hangfire.Pro: 1.4.7.0;
  • Hangfire.Core: 1.6.8.0;
  • Hangfire.Mongo: 0.3.2.201;

1000 jobs are executed every 15 min and 7 jobs at a time.


Message: Hangfire.Mongo.DistributedLock.MongoDistributedLockException: Could not release a lock on the resource ‘HangFire:locks:schedulepoller’: Check inner exception for details. System.UnauthorizedAccessException: Access to the path is denied.

Exception:

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.Threading.EventWaitHandle.OpenExistingWorker(String name, EventWaitHandleRights rights, EventWaitHandle& result)
   at Hangfire.Mongo.DistributedLock.MongoDistributedLock.Release()
   --- End of inner exception stack trace ---
   at Hangfire.Mongo.DistributedLock.MongoDistributedLock.Release()
   at Hangfire.Mongo.DistributedLock.MongoDistributedLock.Dispose()
   at Hangfire.Server.DelayedJobScheduler.EnqueueNextScheduledJob(BackgroundProcessContext context)
   at Hangfire.Server.DelayedJobScheduler.Execute(BackgroundProcessContext context)
   at Hangfire.Server.AutomaticRetryProcess.Execute(BackgroundProcessContext context)

I think the error happens in this line: https://github.com/sergeyzwezdin/Hangfire.Mongo/blob/master/src/Hangfire.Mongo/DistributedLock/MongoDistributedLock.cs#L209

Someone had the same problem? Is there any solution for this?

Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 20 (7 by maintainers)

Most upvoted comments

In Hangfire configuration:

var mongoclient = (IMongoClient)app.ApplicationServices.GetRequiredService(typeof(IMongoClient));
GlobalConfiguration.Configuration.UseMongoStorage(mongoclient.Settings, Settings.Database.DatabaseName, storageOptions);

In Mongo settings:

services.AddSingleton<IMongoClient>(provider =>
            {
                var settings = MongoClientSettings.FromUrl(MongoUrl.Create(Settings.Database.ConnectionString));
                settings.MaxConnectionPoolSize = 200;
                settings.MaxConnectionIdleTime = TimeSpan.FromMinutes(1);
                settings.ConnectTimeout = TimeSpan.FromSeconds(55);
                settings.SocketTimeout = TimeSpan.FromSeconds(55);
                return new MongoClient(settings);
            });

@gottscj The errors I pasted above got solved after configuring more properties on the mongo repository client and the C# driver. Thanks for help!