Handle timeouts of Node Function Apps - node.js

I created an Azure Function App with a Node runtime, which works properly on local and manually created cloud environments.
But when it becomes deployed via Azure Pipelines, it writes a message via context.log and seems working but finally it raises Timeout error.
Timeout value of 00:05:00 exceeded by function 'Functions.<...>' (Id: '<...>'). Initiating cancellation.
I guess, that there is some blocking Node expression because of misconfiguration, but there is no further context logged by Application Insights.
There is a way to handle the cancelation event within your Function App to provide some Node runtime information (e.g. via SIGINT callbacks)?

I've tried to reproduce this issue but failed. But I got some similar question here and noticed we can set functionTimeout value in host.json file. How about trying it.

Related

Azure Function getting 503

I am trying to run an Azure Function App, that we already have running in a different resource group / service plan / storage account. The original app works fine. But when I try to run this one, I get a 503.
The problem is that all I know is that I'm getting the 503. There is no other information. I turned on tracing in the app, but I still get no messages. I have tried to execute the app from both the Azure Portal Function App Code / Test section, and from Postman, with the same results. It spins for a long time, and then I get the 503.
When I try to execute the function, it is showing me the following in the logs:
Request successfully matched the route with name 'IngestRfidScan' and template 'api/v1/rfidScan'
Executing 'Functions.IngestRfidScan' (Reason='This function was programmatically called via the host APIs.', Id=a9c37c44-6a27-41e0-bff8-74fbb4275ecc)
Sending invocation id:a9c37c44-6a27-41e0-bff8-74fbb4275ecc
Posting invocation id:a9c37c44-6a27-41e0-bff8-74fbb4275ecc on workerId:7195f57f-b8ff-4613-84e4-9d4bc5dd7c4a
I don't see any log messages after this. I tried adding logging to the app, but I am not seeing my messages in the log anywhere. So this leads me to believe that it's not executing the function at all. But I can't seem to find any way to determine why. At first I thought it could be a firewall issue, but I don't think I'd see those messages in the log above.
Any ideas how to diagnose this?
Check one of my workarounds to know the reasons of Azure Functions 503 service unavailable error causes.
It is definitely timing out. But I don't know why that is, I don't have enough info in the logs. I checked App Insights, but again, it just tells me the request is timing out, but no explanation.
I have given the timeout limits in the above workaround reference, check that and also the resolution.
For getting the logs / more information, you can check the Diagnose and solve problems menu in the Azure Portal Function App and also my workaround that shows different ways to see the Function App and Host Logs.

Azure Functions - Always On and HTTP Triggers

I am currently looking into occasional slow responses after periods of inactivity for an Azure Function application. The Azure Function runs on a dedicated plan, with host runtime version 1.x, and always on
enabled. The application uses queue messages to trigger the functions.
I noticed the documentation states If you run on an App Service plan, you should enable the Always on setting so that your function app runs correctly. On an App Service plan, the functions runtime goes idle after a few minutes of inactivity, so only HTTP triggers will "wake up" your functions.
I know that always on sends requests from the front-end load balancer to the application root url, however does that mean I have a http triggered function listening at the root url to ensure the function is always on. I tried this in my local development environment with a function which just returns an OK result and it seems to work. But is it necessary?
I would have thought not, as it was based on the web jobs host which just required the application pool to be not idle.
Any clarification would be extremely helpful.
It would appear that the always on functionality is implemented through the use of a rewrite in the web.config of the function host.
A call to the application root url will be forwarded to /admin/host/ping which is part of the host controller.
So in answer to your question
..does that mean I have a http triggered function listening at the root url to ensure the function is always on.
The answer is no.

Is there a way to programmatically restart an azure function

I have an Azure function running on a timer every few minutes that after a varied amount of time of running will begin to fail every time it runs because of an external API and hitting the restart button manually in the azure portal fixes the problem and the job works again.
Is there a way to either get an azure function to restart itself or have something externally restart an azure function via a web hook or API request or running on a timer
I have tried using Azures API Management service which can be used to restart other kinds of app services in azure but it turns out there is no functionality in the API to request a restart of an azure function, Also looked into power shell and it seems to be the same problem you can restart different app services but not azure functions
i have tried working with the API
https://learn.microsoft.com/en-us/rest/api/azure/
Example API request where you can list functions within an azure function
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/functions?api-version=2016-08-01
but there is no functionality to restart an azure function from what i have researched
Basically i want to Restart the Azure function as if i was to hit this button
Azure functions manual stop/start and restart buttons in azure portal
because there is a case where the job gets into a bad state every time it runs because of an external API i have no control over and hitting restart manually gets the job going again
Another way to restart your function is by using the "watchDirectories" setting in the host.json file. If your host.json looks like this:
{
"version": "2.0",
"watchDirectories": [ "Toggle" ]
}
You could toggle a restart by using following statement in a function:
System.IO.File.WriteAllText("D:/home/site/wwwroot/Toggle/restart.conf", DateTime.Now.ToString());
Looking at the logs, the function reloads as it has detected the file change in the directory:
Watched directory change of type 'Changed' detected for 'D:\home\site\wwwroot\Toggle\restart.conf'
Host configuration has changed. Signaling restart
Azure functions by their nature are called upon an event. That may be a timer, a trigger or invocation like a HTTP event. They cannot be restarted per se, i.e. if you a function throws and exception, you cannot find the specific instance and re-run it using the out of the box functionality.
However, you can engineer your way to a more reliable solution:
Replay the event that invoked the function (i.e. kick it off again)
For non-sensitive data, log the payload of the function and create a another function that can be called on demand to re-run it. I.e. you create a proxy to "re-invoke" the function.
Harden your code by implementing a retry policy. See Polly.
Add a service bus in to your architecture. Have a simple function to write the call payload to a message bus payload. Have another function to pick up the payload and process it more extensively where there may be unreliable integrations etc). That way if the call fails you can abandon and dead letter failures for later reprocessing.
Consider using Durable Function Extensions and leveraging the durable patterns, these can help make your functions code more robust and manage state.
Why don't you try below ARM API. Since Azure function also fall under App service category, sometimes this may be helpful,
https://learn.microsoft.com/en-us/rest/api/appservice/webapps/restart

Azure Functions: Application freezes - without any error message

I have an Azure Functions application which once in a while "freezes" and stops processing messages and timed events.
When this happens I do not see anything in the logs (AppInsight), neither exceptions nor any kind of unfamiliar traces.
The application has following functions:
One processing messages from a Service Bus topic subscription (belonging to another application)
One processing from an internal storage queue
One timer based function triggered every half hour
Four HTTP endpoints
Our production app runs fine. This is due to an internal dashboard (on big screen in the office), which polls one of the HTTP endpoints every 5 minutes, there by keeping it alive.
Our test, stage and preproduction apps stop after a while, stopping to process messages and timer events.
This question is more or less the same as my previous question, but the without error message that was in focus then. Much fewer error messages now, as our deployment has been fixed.
A more detailed analysis can be found in the GitHub issue.
On a consumption plan, all triggers are registered in the host, so that these can be handled, leading to my functions being called at the right time. This part of the host also handles scalability.
I had two bugs:
Wrong deployment. Do zip based deployment as described in the Docs.
Malformed host.json. Comments in JSON are not right, although it does work in most circumstances in Azure Functions. But not all.
The sites now works as expected, both concerning availability and scalability.
Thanks to the people in the Azure Functions team (Ling Toh, Fabio Cavalcante, David Ebbo) for helping me out with this.

Google App Engine - nodejs application goes down over night

Hi I am using google app engine to host a single instance nodejs application. The application works fine and my scripts are showing no errors in the logs. The application is currently just in testing and is not getting used over night, however often I come to work the next day and the server is just returning internal server errors. No errors are shown in my application log other then the 502 errors which i get when trying to access the next day. I see like 100s of calls for /_ah/_background/ overnight some appear to have timed out. At this point I must restart my instance for the app to continue to function.
I am completely stumped.. Because my app using web-sockets I must use manual scaling and a single instance. Would appreciate any help / suggestions.
I would venture a gues that you have a deferred task stuck running. Tasks that run in the taskqueue api are set by default to continuously retry. You can visit the taskqueue api TaskQueue API
To get the tasks to stop running right now visit the Google Cloud Console
select your project. Then select App Engine. Then select Task queues. Click on the task that is running (probably default). There should be a option to Pause the queue. This should prevent the 500 errors from occurring but will not fix the reason the task is failing.

Resources