why does a function in an azure function app randomly stop running

Donald Christine 0 Reputation points
2025-02-19T18:22:22.5033333+00:00

We are migrating function apps from an existing subscription to a new subscription. One of the functions in a function app that ran successfully in the previous subscription now starts and then randomly stops running. I can see in the event log the following error which seems to coincide with when the function stops running.
User's image

It is the same code and env variables running in both subscriptions...but the one in the new subscription continues to just randomly stop.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,441 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Suwarna S Kale 786 Reputation points
    2025-02-19T19:34:49.1833333+00:00

    Hello Donald Christine,

    Thank you for posting your question in the Microsoft Q&A forum.

    The error message you provided indicates that the function app is shutting down unexpectedly. This is often related to the hosting environment or runtime issues in the new subscription. The error message (screenshot) you provided tell us below:

    • The function app is hosted on IIS (Internet Information Services) using the ASP.NET Core Module V2.
    • The application is shutting down unexpectedly, which could be due to runtime issues, configuration mismatches, or resource constraints.

    You may try below troubleshooting steps:

    • The web.config file in your function app plays a critical role in configuring the ASP.NET Core Module V2. Ensure that the file is correctly configured for the hosting environment. Ensure that the hostingModel is set correctly (InProcess or OutOfProcess). Misconfigurations here can cause the application to shut down unexpectedly. Useful link https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-6.0
    • Resource constraints, such as exceeding CPU or memory limits, can cause the function app to shut down. So check resource constraints from Azure portal and navigate to your function app --> Metrics --> Add metrics for CPU usage, memory usage, and execution time --> Look for any spikes or limits being hit. Useful link - https://learn.microsoft.com/en-us/azure/azure-functions/functions-monitoring
    • The App Service Plan in the new subscription might differ from the old one. Verify that the plan in the new subscription matches the old one in terms of tier, size, and scaling behavior.
    • Azure Functions rely on an Azure Storage account for triggers and state management. Ensure that the storage account used by the function app is correctly configured and accessible. Check the AzureWebJobsStorage app setting in the function app configuration to ensure it points to the correct storage account. Useful link - https://learn.microsoft.com/en-us/azure/azure-functions/storage-considerations?tabs=azure-cli
    • Ensure that the function app is using the same .NET runtime and Azure Functions runtime versions as the old subscription. Update any NuGet packages or extensions used by the function app to ensure compatibility.
    • Deploy a simple "Hello World" function to the new subscription to verify that the hosting environment is functioning correctly. This helps isolate whether the issue is with the hosting environment or the specific function code.
    • Restart the function app in the Azure portal to clear any transient issues. This can often resolve unexpected shutdowns caused by temporary glitches.

    Unexpected shutdowns in Azure Function Apps after subscription migration can be caused by a variety of factors, including hosting configuration issues, resource constraints, and runtime mismatches.

    If the above answer helped, please do not forget to "Accept Answer" as this may help other community members to refer the info if facing a similar issue.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.