Changing the Azure Function timeout duration. Did you know?

2023, Oct 20

Timeouts are a common issue when working with Azure Functions, specially when you are working with long running processes.

The issue

This is what you could find on App Insights: Timeout value of 00:05:00 exceeded by function 'YourFunction' (Id: '00000000-0000-0000-0000-000000000000'). Initiating cancellation.

The above value of 00:05:00 is the default timeout value for Azure Functions on Consumption Plan. Did you know that you can change that?

On Comsumption Plan you can change the timeout duration to a maximum of 10 minutes. Other plans have different limits.1

The most common fix

To change the timeout duration, add the following to your host.json file:

{
    "functionTimeout": "00:10:00"
}

This is an example of a host.json file, which already contains other configurations:

{
    "version": "2.0",
    "functionTimeout": "00:10:00",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    }
}

The other fix - Azure Configuration

Not very common, but updating the App Configuration is also an option.

For your consumption function apps, add the following appsetting:

AzureFunctionsJobHost__functionTimeout = 00:10:00

Configuration

NOTE: For this to work, make sure to remove the timeout configuration from host.json. If there is a conflict, the configuration from host.json will take precedence.