在Visual Studio中调试Web应用程序时,Hangfire DistributedLockTimeoutException

问题描述 投票:0回答:1

我在调试使用Hangfire处理排队​​的ASP.NET MVP应用程序时遇到问题。当我开始在Visual Studio中调试时(数据库在Azure上远程部署),我收到一堆DistributedLockTimeoutExceptions和RecurringJobScheduler:Debug错误。它仅在调试期间发生。在部署和运行应用程序时,或者在没有通过VS调试的情况下启动应用程序时,都不会出现该问题。

发生的错误是出现错误,然后应用程序一遍又一遍地重试连接至少一个小时(通常大约2-3小时)。在应用程序最终加载之后,对执行的每个操作重复整个过程。

我真的很想调试应用程序,但是随着时间的流逝,它几乎是不可能的,并且经常崩溃。问题在增加。刚开始时,加载应用程序只有几分钟左右,而且变得越来越糟(在开始时,我什至没有看到任何错误,因为加载是可以接受的。)

错误多次发生,但是它们基本上是相同的。经常发生的错误如下:

Hangfire.Storage.DistributedLockTimeoutException: Timeout expired. The timeout elapsed prior to obtaining a distributed lock on the 'HangFire:locks:schedulepoller' resource.
   at Hangfire.SqlServer.SqlServerDistributedLock.Acquire(IDbConnection connection, String resource, TimeSpan timeout)
   at Hangfire.SqlServer.SqlServerConnection.AcquireLock(String resource, TimeSpan timeout)
   at Hangfire.SqlServer.SqlServerConnection.AcquireDistributedLock(String resource, TimeSpan timeout)
   at Hangfire.Server.DelayedJobScheduler.UseConnectionDistributedLock[T](JobStorage storage, Func`2 action)
   at Hangfire.Server.DelayedJobScheduler.Execute(BackgroundProcessContext context)
   at Hangfire.Server.AutomaticRetryProcess.Execute(BackgroundProcessContext context)
Hangfire.SqlServer.ExpirationManager:Debug: Background process 'Hangfire.SqlServer.ExpirationManager' started.
Hangfire.SqlServer.CountersAggregator:Debug: Background process 'Hangfire.SqlServer.CountersAggregator' started.
Hangfire.SqlServer.ExpirationManager:Debug: Removing outdated records from the 'AggregatedCounter' table...
Hangfire.SqlServer.CountersAggregator:Debug: Aggregating records in 'Counter' table...
Hangfire.SqlServer.ExpirationManager:Debug: Removing outdated records from the 'Hash' table...
Hangfire.Server.Worker:Debug: Background process 'Worker #ea15664b' started.
Hangfire.SqlServer.CountersAggregator:Debug: Aggregating records in 'Counter' table...
Hangfire.Server.Worker:Debug: Background process 'Worker #eb7f9473' started.
Hangfire.Server.DelayedJobScheduler:Debug: Error occurred during execution of 'DelayedJobScheduler' process. Execution will be retried (attempt #1) in 00:00:01 seconds.


Hangfire.Storage.DistributedLockTimeoutException: Timeout expired. The timeout elapsed prior to obtaining a distributed lock on the 'HangFire:locks:schedulepoller' resource.
   at Hangfire.SqlServer.SqlServerDistributedLock.Acquire(IDbConnection connection, String resource, TimeSpan timeout)
   at Hangfire.SqlServer.SqlServerConnection.AcquireLock(String resource, TimeSpan timeout)
   at Hangfire.SqlServer.SqlServerConnection.AcquireDistributedLock(String resource, TimeSpan timeout)
   at Hangfire.Server.DelayedJobScheduler.UseConnectionDistributedLock[T](JobStorage storage, Func`2 action)
   at Hangfire.Server.DelayedJobScheduler.Execute(BackgroundProcessContext context)
   at Hangfire.Server.AutomaticRetryProcess.Execute(BackgroundProcessContext context)
Hangfire.Server.DelayedJobScheduler:Information: Error occurred during execution of 'DelayedJobScheduler' process. Execution will be retried (attempt #2) in 00:00:03 seconds.


    System.InvalidOperationException: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()
       at Hangfire.SqlServer.SqlServerStorage.CreateAndOpenConnection()
       at Hangfire.SqlServer.SqlServerConnection.AcquireLock(String resource, TimeSpan timeout)
       at Hangfire.SqlServer.SqlServerConnection.AcquireDistributedLock(String resource, TimeSpan timeout)
       at Hangfire.Server.RecurringJobScheduler.UseConnectionDistributedLock(JobStorage storage, Action`1 action)
       at Hangfire.Server.RecurringJobScheduler.Execute(BackgroundProcessContext context)
       at Hangfire.Server.AutomaticRetryProcess.Execute(BackgroundProcessContext context)
    Hangfire.Server.RecurringJobScheduler:Debug: Error occurred during execution of 'RecurringJobScheduler' process. Execution will be retried (attempt #1) in 00:00:01 seconds.

我已经尝试过重新部署该应用程序,但这并没有太大帮助。我试图在网上浏览一些类似错误的提示,但是它们并没有提供很多见解,所提供的解决方案也无法解决我的问题。我检查了锁表,但这并未包括在内。

除了每30分钟1个作业外,几乎没有任何作业在HangFire上运行,但是它不需要很多资源。否则处理作业几乎没有问题。

任何帮助都将非常受欢迎!

我在调试使用Hangfire处理排队​​的ASP.NET MVP应用程序时遇到问题。当我开始在Visual Studio中调试(数据库在Azure上远程部署)时,我得到了一堆...

c# asp.net-mvc debugging hangfire
1个回答
0
投票

First

© www.soinside.com 2019 - 2024. All rights reserved.