Azure Functions: Extend Execution Timeout Past 5 Minutes 1Azure 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!

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.

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.

GET MORE STUFF LIKE THIS

Subscribe to the Build Azure Weekly newsletter to receive similar updates about Microsoft Azure and related topics!


We respect your privacy and take protecting it seriously. We do not sell our email list, and you can unsubscribe at any time.

Posted by Chris Pietschmann

Chris is a Microsoft MVP and has nearly 20 years of experience building enterprise systems both in the cloud and on-premises. 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.

14 Comments

  1. […] Azure Functions: Extend Execution Timeout Past 5 Minutes (Chris Pietschmann) […]

    Reply

  2. There is a simple typo in the first line of the second paragrah. “It’s important to not that” it is ‘note’ and ‘not’. I like this article. Thank you!

    Reply

    1. Chris Pietschmann September 20, 2017 at 8:21 am

      Fixed. Thanks!

      Reply

  3. What are my options in Azure stack if I wan’t to keep a background task running until explicitly interrupted? I am looking for something other than VM. Loved the server-less architecture of function app but not solution I have been look for. Eg. task could be like collecting twitter stream or constantly looking for change in stock prices, etc.

    Any help is deeply appreciated.

    Reply

    1. Chris Pietschmann September 22, 2017 at 8:21 am

      You could use a Continuously running Web Job.

      Reply

      1. Continuously running a WebJob would require me to deploy a VM, if I am not wrong. Any other way you could suggest ?

      2. Chris Pietschmann September 22, 2017 at 9:38 am

        WebJobs are part of App Service PaaS feature, not VMs. But yes there would still be a Managed VM underneath.

    2. You can have a function or webjob on a timerTrigger.

      Reply

  4. One thing worth mentioning is this timeout only applies when running in an consumption plan. When running in a regular app service plan, no time limit applies and your Functions can run as long as you like. This is covered in the docs https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale

    Reply

  5. […] mins in my environment (19 Management Agents). I increased the timeout to the maximum of 10 mins as detailed here. Essentially added the following to the host.json file in the wwwroot directory of my Function […]

    Reply

  6. Why not use durable tasks ? Only thing u need to take care of is modularity of your code. And knowledge of Durable Task Framework.

    Reply

  7. […] Azure Functions: Extend Execution Timeout Past 5 Minutes […]

    Reply

  8. Divya Poojari June 5, 2019 at 11:25 am

    Hi Chris,

    Thanks for the info, however I have couple of doubts,
    1) Is this configuration needed for app service plan, as I have read in couple of sites that app service plan has indefinite time limit
    2) I have written durable function (function chaining), and when the last activity trigger is called and waiting for the response, it timed out even after introducing this configuration. In the background, the called method is being executed. Could you please help what could be the issue here?
    Thanks in advance.

    Reply

    1. Chris Pietschmann July 1, 2019 at 11:56 pm

      1) App Service Plans do not have any timeout limit for Azure Functions running, so this setting is not needed there.
      2) The orchestrator function with Durable Functions can have an overall execution time longer than the limit since it delegates tasks out to asynchronously running Functions. If you have loops or other activities within the orchestrator function, then you could hit up against the timeout limit there though. Each of the individual Functions running within the chain will still be limited to the execution timeout limit for each Function; at least if your using Consumption Plan pricing.

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.