【问题标题】:Hangfire DisableConcurrentExecution: What happens when the timeout expires?Hangfire DisableConcurrentExecution:超时到期时会发生什么?
【发布时间】:2016-11-09 21:02:16
【问题描述】:

根据Hangfire 0.8.2 announcement post,Hangfire 有一个DisableConcurrentExecution 过滤器,当应用于一个方法时,可以防止该方法的多个实例同时执行。

DisableConcurrentExecution 过滤器采用 timeoutInSeconds int 参数。从链接文章中的示例:

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

我的问题是:如果一个作业正在等待获取DisableConcurrentExecution-filtered 方法的锁,而该作业等待的时间超过了timeoutInSeconds 值,会发生什么情况?

【问题讨论】:

  • 注意:如果你有任务在等待,它们会阻塞等待释放锁的工作线程。因此,如果您有意或无意地依赖此属性来按顺序运行项目,请务必小心,因为您可能会阻止其他任务也运行。

标签: c# hangfire


【解决方案1】:

我最近测试过。该作业实例在仪表板中记录为失败,并列出了表明在等待排他锁时超时已过期的异常。

您会看到以下异常:

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)

【讨论】:

  • 给你,更详细的异常信息(抱歉没有格式化):Hangfire.Storage.DistributedLockTimeoutException: Timeout expired。在“xxx”资源上获得分布式锁之前超时已过。在 Hangfire.SqlServer.SqlServerDistributedLock.Acquire(IDbConnection 连接,字符串资源,TimeSpan 超时)
  • 我有一个非常相似的问题,这是一个经常性工作的常见问题,太难过了......
猜你喜欢
  • 1970-01-01
  • 2016-03-12
  • 1970-01-01
  • 2019-06-29
  • 1970-01-01
  • 1970-01-01
  • 2022-08-03
  • 1970-01-01
  • 2011-07-12
相关资源
最近更新 更多