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!

Pricing Tier Timeout 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 timeouts for the Premium and Dedicated pricing tiers.

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:

Pricing Tier Default Timeout Minimum Maximum
Consumption Plan 5 min 1 min 10 min
Premium Plan 30 min 1 sec 60 min
App Service Plan 30 min No limit (set using -1 value

* Regardless of the Function App Timeout configuration, 230 seconds is the maximum amount of time that an HTTP Triggered function can take to respond to a request.

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"
// Set functionTimeout to 60 minutes (1 hour)
    "functionTimeout": "01:00:00"
// Set functionTimeout to "No Limit"
// Generally not recommended, just in case of infinite loop scenarios
    "functionTimeout": "-1"

The functionTimeout in the host.json file can be configured using a timespan string format ranging from a minimum of 1 second (00:00:01), up to a maximum of 10 minutes (00:10:00) for Consumption Plan hosting and Unlimited (-1) for Premium and Dedicated Plans . Remember, the default without overriding the setting will be 5 minutes (00:05:00) or 30 minutes (00:30:00) depending on the hosting plan type used.

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 for the Function App as it’s hosted within the internal App Service Plan.

Edit host.json file within Azure Portal

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. This is something that can be done within the Azure Portal without requiring you to republish the Azure Function source code. However, when doing this, it is not recommended to do in production if you are using a CI/CD pipeline to deploy the code of your solution.

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 within the Azure Portal.
  2. In the list of options on the left-side, select the App Service Editor option underneath the Development Tools section, then click the Go link to open the App Service Editor.
    Azure Functions: Extend Execution Timeout Past 5 Minutes 2
  3. The App Service Editor will open in a new browser tab. As you can see, the editor has a similar UI to what you may already be familiar with in Visual Studio Code.
  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 3

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.

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 using the Durable Functions capabilities of Azure Functions. 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 4

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.

Microsoft MVP

Chris Pietschmann is a Microsoft MVP, HashiCorp Ambassador, and Microsoft Certified Trainer (MCT) with 20+ years of experience designing and building Cloud & Enterprise systems. He has worked with companies of all sizes from startups to large enterprises. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.
HashiCorp Ambassador Microsoft Certified Trainer (MCT) Microsoft Certified: Azure Solutions Architect