504 gateway timeout azure durable function

Viewed 46

I am using this tutorial to create azure durable function https://docs.microsoft.com/en-us/azure/azure-functions/durable/quickstart-js-vscode

Note:- I am using premium plan

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  },
  "functionTimeout": "00:40:00"
}

Hello/index.js

function delay(sec) {
  let now = Date.now();
  // run while loop for - sec
  while (now + sec * 1000 > Date.now());
}
module.exports = async function (context) {
  context.log("I am starting.");
  const startTime = new Date().toLocaleTimeString();

  // simulating a long-running task
  delay(5 * 60);
  const endTime = new Date().toLocaleTimeString();
  return `${context.bindings.name} - ${startTime} -> ${endTime}`;
};

Sometimes call to the function HelloOrchestrator is working fine, but sometimes it responds with 504 gateway timeout.

What could be the issue?

1 Answers

You did not share your whole code but it looks like you may be delaying a HTTP triggered function beyond 230 seconds which is the default idle timeout of Azure Load Balancer. That will lead to a 504 gateway timeout error.

From Azure Function app timeout duration:

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. This is because of the default idle timeout of Azure Load Balancer.

Note that you should ideally only schedule an orchestrator in the HTTP trigger which normally takes some milliseconds and return an HTTP response. When the scheduled orchestrator runs, it can call an activity function which could be a long-running background task

Related