Azure Functions: Extend Execution Timeout Past 5 Minutes 1

Azure Functions is the Serverless compute option within the Microsoft Azure platform. One of the biggest benefits of Azure Functions, and Serverless compute, is that you only pay when your code is actually executing. However, there has been a limitation of Azure Functions in the duration of how long a Function of code can run. This execution time was limited by a hard limit originally set to 5 minutes. For background processes that can be very limiting under certain circumstances. Thankfully, there has recently been an update to Azure Functions that allows you to configure your Azure Functions “maximum execution timeout” to be a little higher!



Timeout vs Function Chaining

It’s important to note that the recommended approach to using Azure Functions and Serverless compute is to use architectural patterns like Function Chaining, among others. Function Chaining is a method of breaking up a long running task into multiple shorter running tasks and then linking them together so that each one call the next in the workflow once it completes. This essentially can free you up from the limited time constraints imposed by the Azure Functions Runtime that limits the maximum amount of time a Function can execute before it would be automatically killed off.

Azure Functions: Extend Execution Timeout Past 5 Minutes 2

The original, default timeout for an Azure Function was 5 minutes. This meant that if the Azure Function was running for an elapsed time period of 5 minutes, then the Azure Functions Runtime could end the process at any point after that. Now, it’s not guaranteed that it will end the process and kill the Function being executed, but it’s possible. It’s also not guaranteed that if the Functions takes 1 second longer than 5 minutes that it’ll be allowed to finish execution. Overall, this is a big limitation over the alternative of using Azure Web Jobs which do not have any execution runtime timeout limitation.

Pricing Tier Differences

The Azure Function Timeout is difference depending on which hosting method / pricing tier is used to host an Azure Function App. While in the Consumption plan, the default timeout is 5 minutes, there is a different default and maximum timeout for the App Service Plan and Premium Plan pricing.

Here are the different timeouts for each of the Azure Functions pricing tiers, along with the default and maximum values that can be set using the functionTimeout configuration property within the host.json file:

  • Consumption plan
    • Default: 5 minutes
    • Minimum: 1 minute
    • Maximum: 10 minutes
  • Premium plan
    • Default: 30 minutes
    • Minimum: 1 second
    • Maximum: 60 minutes
  • Dedicated (App Service) plan
    • Default: 30 minutes
    • Maximum: No Limit (set using a -1 value)

The pricing tier used to host an Azure Function App needs to be factored into the decision on what the individual function execution timeout will be for functions within that app. Also, if it’s known that certain functions will take longer to execute, then the appropriate pricing tier should be chosen for hosting.

In relation to the Dedicated (App Service) plan function timeout, there is no upper limit on the execution timeout. To enable “unlimited execution time” the functionTimout configuration can be set to the value of -1. However, it is strongly recommended to keep a fixed upper bound so the app is prevented from getting into infinite loop scenarios.

functionTimeout Configuration in host.json

In a recent update, the Azure Functions team at Microsoft has added a configuration option that enables an Azure Functions App to have the timeout increased. To implement this, the “functionTimeout” property within the “host.json” file for an Azure Function App can be set to a timespan duration of 10 minutes.

// Set functionTimeout to 10 minutes
{
"functionTimeout": "00:10:00"
}

// Set functionTimeout to 5 minutes
{
"functionTimeout": "00:05:00"
}

The “functionTimeout” in the “host.json” file can be configured to timespans ranging from a minimum of 1 second (00:00:01), up to a maximum of 10 minutes (00:10:00). Remember, the default without overriding the setting will be 5 minutes (00:05:00).

The “host.json” file is a global configuration file for an Azure Functions App. This means that the configuration settings within this file will be applied to all functions hosted within that Azure Functions App. Being a global configuration file for the Function App, it doesn’t reside in the files for a particular Azure Function. Instead, the “host.json” file resides within the main “wwwroot” folder / directory for the Function App as it’s hosted within Azure App Service Plan.

To access and edit the “host.json” file, the simplest approach is to open the App Service Editor (an online IDE of sorts) for the App Service that’s hosting the Azure Functions App. To access the App Service Editor for an Azure Function App, you can follow the below steps to edit the “host.json” configuration file:

  1. Open the Azure Function App blade within the Azure Portal, and click on the Platform features tab at the top of the blade.
    Azure Functions: Extend Execution Timeout Past 5 Minutes 3
  2. On the Platform features tab of the Azure Function App blade, location the Development Tools section of links, and click on App Service Editor.
    Azure Functions: Extend Execution Timeout Past 5 Minutes 4
  3. The App Service Editor will open in a new browser tab.
  4. Locate the host.json file underneath the WWWROOT folder / directory within the App. By default this file will be empty. You can then add the functionTimeout property and set it to your desired timeout threshold, such as 10 minutes (00:10:00).
    Azure Functions: Extend Execution Timeout Past 5 Minutes 5

It’s important to know that the App Service Editor will auto-save ALL changes. This means that you want to be especially careful if you use the App Service Editor in a Production environment. Any typos, or messed up configurations could have adverse affects on the App and potentially cause downtime. Please, use the App Service Editor at your own risk for this reason. In a Dev or Test environment, then you’ll likely be fine as you can always just go back and fix any mistakes easily.

Other options to edit the “host.json” file for an Azure Function App are to use FTP or other deployment tools supported by Azure Functions for managing the deployment process.


Microsoft MVP

Chris is a Microsoft MVP and has nearly 20 years of experience designing and building Cloud & Enterprise systems. He is also a Microsoft Certified Azure Solutions Architect and developer, a Microsoft Certified Trainer (MCT), and Cloud Advocate. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.

Pin It on Pinterest