Azure Function Timeout on Consumption Plan - azure

I've specified a timeout on my http trigger azure functions (v1) by specifying the following in my host.json file
{
"functionTimeout": "00:10:00"
}
I've deployed to Azure using VS2017 and can confirm that this setting now appears in the Azure Portal. I also restarted the function app just to be sure.
When I execute my function, it is always timing out on or around 4 minutes, even though the timeout has been set to 10 minutes
I've ruled out the timeout occurring from other sources as when I test the Azure function locally it does not time out.
Can anyone shed some light on why this is happening?

It is expected. Http request has a fixed timeout setting on Azure site. See Azure Web App timeout setting of 230s. In this aspect, there's no difference between Azure Web app and Http trigger Azure Function.
There is a 230 second (i.e. a little less than 4 mins) timeout for requests that are not sending any data back. After that, the client gets the 500 you saw, even though in reality the request is allowed to continue server side.
As for how to bypass this limitation, if it's not necessary to get an immediate feedback like httpresponse, you can use queue trigger to do your job.
Otherwise, have a look at Durable function. You could send an http request to start an orchestrator and get a response that it starts successfully and so on. The work is being processed in orchestrator and activity function and we don't need to worry about time out(as they are non-http trigger as well).

Azure Functions team at Microsoft has added a configuration option that enables an Azure Functions App to have the timeout increased.
Full answer #Build5Nines.com Azure Functions: Extend Execution Timeout Past 5 Minutes
In short edit host.json and set functionTimeout:
// Set functionTimeout to 10 minutes
{
"functionTimeout": "00:10:00"
}

Related

Logic App returns a Gateway timeout error even after 30 secs

I have a logic app that gets called from APIM > Function > Logic app > D365 (synchronous call based on http request trigger). When I call it the first time (after a day, or after a few hours), takes longer than usual (around 25-30 seconds) and results in a Gateway timeout error.
When I call it the second time, it usually completes the operation within 8-10 secs with no timeouts.
The error message is typical:
The execution of template action 'Response_-_to_be_displayed' is failed: the client application timed out waiting for a response from service. This means that workflow took longer to respond than the alloted timeout value. The connection maintained between the client application and service will be closed and client application will get an HTTP status code 504 Gateway Timeout.
While keeping the pattern synchronous, i don't think this is something that may cause a timeout issue. I have already checked this link and this one too, but that's not a solution to my problem.
I want to keep the call synchronous (it's only a 25-30 sec call), is it something to do with an APIM policy or any settings in logic apps that can increase this?
you can increase the timeout in both logic app and APIM. In the case of APIM we implement a policy, which will dictate the timeout and in logic app it's app settings.
But in case of APIM if the timeout is more than 240 sec then APIM won't be reliable, and it is advised to look for the implementation of the function.
Now to increase the timeout in APIM we must set up the forward request policy and this policy has the attribute of timeout which you can set to your desired limit.
Go to policy fragments in APIM and add the following to a policy
<forward-request timeout="60"/>
Now regarding the logic-app, we can setup custom timeout by setting up application settings. For this you would need two setting one is threshold and other one is time out. you have to add these in app setting which is under configuration in portal for logic app.
The settings are called
Runtime.FlowRetentionThreshold
and
Runtime.Backend.FlowRunTimeout
the values of these settings are in format Days.hours:Minutes:seconds for example : 00.00:05:00 this one is for 5 minutes
Also please check that your function is working properly as workflow timeout in logic apps and apim timeouts default value is more than the time it takes to execute a task according to you.
Refer this msDoc on Logic app timeout
Refer this msdoc on apim timeout.

Azure functions - Functions host is not running

I keep getting an error 503 on my health checks for my azure functions, it says error 503. Functions host is not running. It's very inconsistent and only happens once every few days, I'm on the consumption plan but looking at whether a premium plan would fix the issue.
In Azure Functions, 503 service unavailable causes for the reasons like:
Function host is down/restarting
Platform issue due to the backend server not running/ allocated
Memory leak/issue from the code causing the backend server to return 503
To get some insights about the function host related issues, take a look into the "Diagnose and solve problems" blade in the Function app and select the "Function app down or reporting" detector. This detector will show all the diagnostic information about the function app and its infrastructure.
503 service unavailable comes sometimes when the function takes more than 5 minutes to return an HTTP response in consumption plan. Regardless of the function app timeout setting, 230 seconds is the maximum amount of time that an HTTP triggered function can take to respond to a request.
For longer processing times, use Azure Durable Functions async pattern. Refer to this link.
We should not change the app settings frequently in the production environment. If you update the app settings, the app will be restarted. In this cases, you will get 503 error. In order to avoid this, you can use the slot feature
Function host is not running
This issue happens due to invalid host.json. To diagnose, it's best to look at the function host logs from the log stream in Azure Portal.
Few errors and resolutions of this kind of error are:
If you have any startup.cs class, check if any error available where the errors were logged in Application Insights.
One of the reason is a missing app setting. Ensure you publish local settings as well.
If it didn't help then one of the reason could be platform issue and to confirm this we need to look into the backend logs on what was happing during that time resulting in 503 errors.
You can create the support ticket with Microsoft to assist you further.
According to this thread, one possible cause of 503 service-unavailable responses is when the service consumes more memory than what is available under the consumption (serverless) plan, causing the service to be evicted. Switching to a dedicated hosting plan can fix this issue. According to Microsoft's documentation, it appears that the function is allowed a maximum of 1,536MB of memory at one time. Of course, it could also be the case that your function is exceeding any of the other service limits associated with that plan, so my advice would be to add instrumentation and code defensively.
Got 503 after redeploying an Azure function.
Turned out the Python version had defaulted to 3.6, updated to 3.9 and started working.
I was using terraform and github actions

Azure Webapp Request returning 502 after 4 min

I know this has been asked before, but I tried all known solutions and still no luck. I have a request that returns roughly 26MB of JSON. It is returning a 502 on my azure web app. I have set maxRequestLength and maxAllowedContentLength to their max allowed values as detailed here.
How to set the maxAllowedContentLength to 500MB while running on IIS7?
I have also set the applicationHost.xdt on the site folder of my webapp and verified it is applied as detailed here.
ApplicationHost.xdt in Azure Web Apps
None the less, my request timeout at exactly 4 minutes every time. I can run the same request against my localhost running on iisexpress pointed to the Azure SQL database and it returns the data, so I know this is something azure webapp speciic.
I have enabled all types of logging in "App Service Logs" section of my webapp. I see other failed request traces for 401 when session expires, but this request doesn't log a failed request trace, or an application error. In live log stream it shows the request as a 200 response in the web server logs.
Any other ideas?
Thanks for a detailed question and sharing the solutions that you have already tried. I'm unsure if "Always ON" feature is turned on on your WebApp. Such time-out error may occur due this,so kindly enable it and let us know for further investigation.
Additional information, Azure Load Balancer has a default idle timeout setting of approximately four minutes (230 sec); this is a general idle request timeout that will cause clients to get disconnected after 230 seconds. However, the command will still continue running server-side after that. For a typical scenario, this is generally a reasonable response time limit for a web request. In such scenarios, you could look at async methods to run additional reports. WebJobs or Azure Functions is another option.
If ‘Always On’ config is not turned On, please do turn it on. The AlwaysOn would help keep the app loaded even when there's no traffic, it will send a request to the ROOT of your application. Whatever file is delivered when a request is made to / is the one which will be warmed up and this feature comes with the App Service Plan is not charged separately
1) From the Azure Portal, go to your WebApp.
2) Select Settings> Configuration > General settings.
3) For Always On, select On.

Queue triggers not working directly after deployment

I have a (C#-based) Function App on a consumption plan that only contains queue triggers. When I deploy it (via Azure DevOps) and have something written to the queue, the trigger does not fire unless I go to the Azure Console and visit the Function App. It also works to add an HTTP trigger to the App and call that. After that, all other triggers work.
The same phenomenon is observed with Timer triggers.
My hypothesis is that these triggers only work when the runtime is active but not directly after deployment when no runtime was created. Is that true? If so, what is the suggested way around this?
My only workaround idea is to add an HTTP trigger and fire regular keepalive pings to that trigger. But that sounds wrong.

How can increase Azure App Service 230 sec request time out

I have hosted an Asp.NET MVC application on Azure App Service. I am getting a timeout exception which elapsed more than 230 seconds. How can increase it on Azure App Service?
As far as I know, 230 seconds is the maximum amount of time that a request can take without sending any data back to the response.
We couldn't increase it in azure web app.
Here are two work around.
One is you could move your application to a cloud service or created a VM where you have control over those settings.
Another way, you could also use async pattern in MVC.
For example:
Firstly, you could send the request to the MVC to tell the server start to work and returns an http 202.
Then you could send request every seconds or minutes from client to check the server work. If it works completely return 200 to tell the client has already completely.

Resources