Azure Functions: Timeout value of 00:05:00 exceeded by function

Raymond Tang Raymond Tang 0 5873 4.26 index 9/17/2021

When running Azure functions, I encountered the following error:

2021-09-17T08:13:47.525 [Error] Timeout value of 00:05:00 exceeded by function 'Functions.***Func' (Id: '32daf701-18de-467c-b36e-b0b7********'). Initiating cancellation.

Root cause

By default, Azure function will timeout in 5 minutes. The maximum for consumption plan is 10 minutes.

When a function timeouts, there are a few activities we need to do:

  • Look into the logs to identify what caused the time-out. You can enable application insights for your Azure Functions app if you have not done that.
  • Configure retry policy when a function fails.
  • Split or refactor your function code to smaller functions. For instance, instead of sending 100 emails in one function, send 10 emails per function execution, etc.

Configure retry policy

Retry policy can be configured through host.jsonfor all functions in the application.

{
  "version": "2.0",
  "retry": {
    "strategy": "fixedDelay",
    "maxRetryCount": 10,
    "delayInterval": "00:00:10"
  },
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  }
}

The above configuration will retry 10 times with 10 seconds interval.

If you want to configure retry policy at function level, you can use properties if you are using C#:

[FixedDelayRetry(5, "00:00:10")]

For more details, refer to official documentation: Azure Functions error handling and retries.

Configure timeout

You can also change the default timeout for function via host.json:

 "functionTimeout": "00:10:00"

The above configuration increases timeout from 5 minutes to 10 minutes for Azure Functions with hosting model as consumption plan.

azure azure-functions

Join the Discussion

View or add your thoughts below

Comments