SWA Azure Function backend returns 500 after 45 seconds, even though function keeps running afterwards

Pritesh Patel 1 Reputation point
2023-09-05T11:00:32.96+00:00

I'm working on a Static Web App using the integrated Azure Functions backend. I have a function that takes about 2.5 minutes to complete due to a large database creation with default entries in the function. I am having an issue where after exactly 45 seconds, the function call returns a 500 error "Backend call failure". Through the database creation process in MySQL workbench, I can tell the function is still running after this event.

The function will run to completion but I can not receive a response from the function after the 500. After the function finishes running I can look at the complete database with default entries inserted into the newly created database.

This issue is present in my deployed Staging Environment, but not when running locally. When I run locally the function behaves as expected.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,930 questions
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,178 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,941 Reputation points Moderator
    2023-09-06T13:48:38.6233333+00:00

    @Pritesh Patel Thanks for reaching out. Can you please check and confirm till what time (in minutes) your function executed and returns the 500 error.

    500 errors could happen due to multiple reasons due to unhandled exceptions in your code or function app timeouts.

    It sounds like you are experiencing a timeout issue with your Azure Function. By default, Azure Functions have a timeout duration of 5 minutes for the Consumption plan and 30 minutes for the Premium and Dedicated plans. However, there is a maximum timeout duration of 10 minutes for the Consumption plan and unlimited for the Premium and Dedicated plans.

    Based on the information you provided, it seems that your function is taking longer than the default timeout duration to complete, which is causing the 500 error. To resolve this issue, you can try increasing the timeout duration for your function by setting the functionTimeout property in the host.json file

    {
      "version": "2.0",
      "functionTimeout": "00:10:00"
    }
    

    If increasing the timeout duration does not resolve the issue, you may want to consider using Durable Functions to handle long-running processes. Durable Functions allow you to write stateful functions that can run for an extended period of time and can be paused and resumed as needed.

    The function will run to completion but I can not receive a response from the function after the 500. After the function finishes running I can look at the complete database with default entries inserted into the newly created database.

    It is the expected behavior in case if function timeout then it returns 500 error. But to know the cause of the 500 error you can review the diagnosis and solve blade on your function app.

    This issue is present in my deployed Staging Environment, but not when running locally. When I run locally the function behaves as expected.

    Different function plan/SKU has different capacity to run your code and the code may take higher time to execute if you are running in consumption plan where there is limited capacity.

    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.