Azure Functions host was shutdown when an error occurs

203 Views Asked by At

An error has occurred in my function app and it was shutdown. "Singleton lock renewal failed for 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."

And then it logged this error and was shutdown

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

This occurred in executing a timer trigger function. How can we prevent the host from shutting down when this or any other error happens? Is there a way to catch the exceptions that occur in host? I am using functions version 2.x.

I am just looking to prevent the app from shutdown/crashing.

1

There are 1 best solutions below

0
SiddheshDesai On

In order to resolve 409 errors with the Function app, Make sure you use different storage accounts for different Function Apps. When the same storage account is shared between 2 or more functions they all write to the same storage account blob and leases. In order to avoid this error:-

Refer this Github comment by ThomasArdal

  • Make sure you use different storage account to avoid this collision.
  • Explicitly specify the host ID of the Function in the Functions settings like below:-

enter image description here

enter image description here

Also, Try implementing these setting to make the singleton behaviour successful in your Function app:-

host.json reference for Azure Functions 2.x | Microsoft Learn

{
    "singleton": {
      "lockPeriod": "00:00:10",
      "listenerLockPeriod": "00:02:00",
      "listenerLockRecoveryPollingInterval": "00:01:00",
      "lockAcquisitionTimeout": "00:02:00",
      "lockAcquisitionPollingInterval": "00:00:02"
    }
}