发生错误时 Azure Functions 主机被关闭

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

我的函数应用程序发生错误并已关闭。 “blob 的单例锁更新失败

with error code 409: LeaseIdMismatchWithLeaseOperation. The last successful renewal completed at 2023-12-15T20:43:56.694Z (130861 milliseconds ago) with a duration of 6 milliseconds. The lease period was 60000 milliseconds."

然后它记录了此错误并被关闭

"An unhandled exception has occurred. Host is shutting down."

这发生在执行定时器触发功能时。当发生此错误或任何其他错误时,我们如何防止主机关闭?有没有办法捕获主机中发生的异常? 我正在使用函数版本2.x。

我只是想防止应用程序关闭/崩溃。

azure azure-functions azure-webjobs
1个回答
0
投票

为了解决函数应用程序的 409 错误,请确保为不同的函数应用程序使用不同的存储帐户。当同一个存储帐户在 2 个或多个函数之间共享时,它们都会写入同一存储帐户 blob 并租用。为了避免这个错误:-

参考此 Github 评论 ThomasArdal

  • 确保使用不同的存储帐户以避免这种冲突。
  • 在功能设置中显式指定功能的主机 ID,如下所示:-

enter image description here

enter image description here

另外,尝试实现这些设置以使单例行为在您的 Function 应用程序中成功:-

Azure Functions 2.x 的

host.json 参考 |微软学习

{
    "singleton": {
      "lockPeriod": "00:00:10",
      "listenerLockPeriod": "00:02:00",
      "listenerLockRecoveryPollingInterval": "00:01:00",
      "lockAcquisitionTimeout": "00:02:00",
      "lockAcquisitionPollingInterval": "00:00:02"
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.