Azure Compute

Azure Functions: Extend Execution Timeout Past 5 Minutes

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.

Configure functionTimeout 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.

Azure Functions Best Practices: Are you interested in learning best practices tips on building Azure Function Apps? Then you’ll want to read the “Azure Functions Best Practices for Performance, Reliability and Security” article written by Chris Pietschmann.

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.
  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).

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.

Diagram: Visualization of Function Chaining
Diagram: Visualization of Function Chaining

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.

Related Articles

36 Comments

  1. Vamsi K K August 24, 2017

    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!

    1. Chris Pietschmann September 20, 2017

      Fixed. Thanks!

  2. Soumyo Dey September 22, 2017

    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.

    1. Chris Pietschmann September 22, 2017

      You could use a Continuously running Web Job.

      1. Soumyo Dey September 22, 2017

        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

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

    2. Brad F October 5, 2017

      You can have a function or webjob on a timerTrigger.

  3. Ben Coleman (@BenCodeGeek) October 17, 2017

    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

  4. Pushkar Saraf June 13, 2018

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

  5. Divya Poojari June 5, 2019

    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.

    1. Chris Pietschmann July 1, 2019

      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.

  6. Chris P April 23, 2020

    hi Chris,
    I am using Consumption Plan for Dev environment and Premium Plan for Live using CICD to do deployment. do you know any way for not overwriting the timeout which already set in each environment.

    1. Chris Pietschmann April 25, 2020

      You can leave the default timeout in place, and you don’t need to overwrite it with a different value.

  7. Baburaj August 3, 2020

    hi Chris, I have an Azure function .net code deploying through Azure pipeline. How do I edit the host.json? When i try to edit, it says that i cant edit because it is deployed through CICD. Where should i keep host,json in my project package? I tried to keep in root folder of project package, but if did not picked

    1. Chris Pietschmann September 4, 2020

      You’ll need to modify your build pipeline to perform any modifications to the host.json file.

  8. Sharath K S August 28, 2020

    Hi Chris Pietschmann, I have a QueueTriggered function app developed in Python, running under Premium Plan and in host.json I have given timeout value to 2 hours, but it was failing with error “Timeout value of 02:00:00 was exceeded by function: Functions.myFunction”. So I changed 2 hours to 4 then to 6 hours as there continued to get same timeout issue.
    Later on I have given timeout to 23:59:59 ( I know it sounds ridiculous, but with frustration I gave this much value). But to my surprise still I get error: Timeout value of 23:59:59 was exceeded by function: Functions.myFunction
    Can you suggest me any solution here?

    1. Chris Pietschmann September 4, 2020

      Have you tried troubleshooting your code and ensuring there isn’t any kind of infinite loop condition occurring?

  9. Manjunath September 8, 2020

    Hi Chris Pietschmann, We are running a function under app service plan and added function timeout as ‘-1’. But it is giving function timeout exception after 30 Min. Our target framework is 3.0.

    1. Chris Pietschmann September 8, 2020

      It’s possible the change you are making to the `host.json` file is getting overridden. How are you modifying the `host.json` file? If you are modifying the `host.json` file in the Azure Function App and then deploying your code it would be getting replaced with the code deployment.

  10. Jack September 21, 2020

    Chis thanks for your various articles – I ended up here from you review of how to decide which service to use func apps, webjobs etc- In that article you mentioned the ability to share an app service plan – which I have seen when create app-x resources – what does this exactly mean ? If I create multiple func apps, webjobs etc I will be charged at that rate – total – or will I be charged the multiple – for example if I have 2 function apps under a premium tier which is at 150/mo – will I be charged a total of 150 or 300 ? I realize there are other considerations in the pricing matrix this is just for simplicity

    1. Chris Pietschmann September 21, 2020

      With App Service Plan you are billed by the number of instances of the App Service Plan. Be default an App Service Plan has only a single instance, and you will only pay for that 1 instance if you host multiple Function Apps, App Service Web Apps, etc on that same plan. Think of an App Service Plan as a VM, or with scaling to multiple instances as multiple VMs. You will pay for the number of instances of the App Service Plan, not the number of apps hosted on that plan.

  11. stevienaps November 18, 2020

    access denied to edit host file? 🙁 any ideas? I looked on stackoverflow

    1. Chris Pietschmann December 4, 2020

      Did you deploy a precompiled function app? That could be why.

  12. Ankush January 5, 2021

    Is function timeout applicable on Azure timer triggered functions as well ?

    1. Chris Pietschmann January 5, 2021

      Yes

  13. ayush1303 March 2, 2021

    I have multiple functions in my function app
    For some of them I want timeout to be 5 min and for one of them i want to keep it around 2hr
    Will it be possible to keep diff timeout for fun in same fun app?

    1. Chris Pietschmann April 20, 2021

      No, the execution timeout is for the Function App, not the individual functions.

  14. munnah August 17, 2022

    guys , i want to create a simple function to trigger every minute and in that function i want it wait for 5 minutes. Just like in bash sleep for 5 minutes and done. Please tell me how can i do this . i just want to monitor the functions behaviours that is my purpose for making the function to wait for 5 minutes.

  15. Satyapal yadav November 9, 2022

    Hi chris I have create simple trigger azure function from portal in .NET 6 with App service plan when I trigger this function url from postman so getting timeout after 4 min in code just add 5min sleep can you suggest here

    1. Chris Pietschmann November 14, 2022

      Are you sure it’s a regular App Service Plan and not a consumption based App Service Plan? Also, you may need to update the timeout config to make sure it’s what you need.

  16. Allabasha December 1, 2022

    Hi Chris,

    How can I disconnect from the domain connected through Powershell in Azure functions

    1. Chris Pietschmann December 14, 2022

      I’m note sure I understand what you’re asking. What do you mean by “domain”?

  17. Diego December 28, 2022

    Hello Chris, a pleasure, I have a selenium script that I am executing in a function app through a docker image, the entire script lasts approximately 20 minutes, a vm is not optimal for my use case because it has a higher cost, Is it optimal to use app function for this use case? What would you recommend in the future? in terms of saving money and ideal implementation?

    1. Chris Pietschmann January 17, 2023

      If you can’t make your script / function run within the timeout limit, then the best course of action is to pay the cost for a different hosting option, or break up the Function into multiple smaller functions. You my want to look into Durable Functions, or simply re-architect your function into a more granular instead of a monolithic one.

  18. kofesa March 17, 2023

    Can we parametrize this property(functionTimeout) to use values from app configuration, or any other way?

    1. Chris Pietschmann March 20, 2023

      You can not parameterize the settings configured within the host.json file. The reason for this is the Function Runtime Host is reads the host.json when it starts up the app. This occurs before the app settings or other parameters are even read or any application code is executed.