Devesh Sharma
Devesh Sharma

Reputation: 975

Http trigger Azure Function v2 (python) executes the entire logic as per expectations but gives 504 Gateway timeout after 4 mins on web request

I have created a Http-Triggered Python Azure Function which takes 3-10 mins to process the entire business logic depending upon the data size.

While triggering this function using postman or python web request, it only waits for the response till 4 mins. If the function executes by that time it gives expected response otherwise it returns 504 Gateway Time-out error. Even while it gives 504 error on the request side, the azure function process the entire load as per expectations and does not fails.

Since the response of the request is responsible for next steps in the pipline so it becomes important for me to capture it. I have tried it for both Get and POST requests.

Can anyone help me to get over this problem?

Upvotes: 1

Views: 3158

Answers (2)

Devesh Sharma
Devesh Sharma

Reputation: 975

Finally, I figured out a fix to the problem I was facing.

Let me reiterate my complete scenario here:

Complete Scenario: I had an ADF pipeline, and an Azure function is one of the component of it, followed by various other. The original problem occurred when my AF takes about 30 min to execute the business logic and the default timeout response is thrown by AF after 4 mins automatically, which breaks the flow and does not execute the next items in the AF pipeline which should run after successful completion of AF component in an ideal scenario.

Solution: I broke a single pipeline to 2, and connected the two pipeline using azure logic app. Let me explain the connection between dots now.

I converted the azure function to process all the time-taking tasks in a demon thread and returned a response to my HTTP request. This resolved my 4 min timeout issue. Now second problem is to trigger the next components in the pipeline after completion of Azure Function(time-taking tasks). So I created a http trigger logic app and triggered it at the end of task completions in Azure Function. This logic app in-turn, trigger the next pipeline and executes the components in a cascaded manner.

Upvotes: 0

silent
silent

Reputation: 16238

As stated here:

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. For longer processing times, consider using the Durable Functions async pattern or defer the actual work and return an immediate response.

So it is not your Function that times out, but because it is an http-triggered one, it's the LB in front.

You should implement your long running process differently. For example receive the data via an http-triggered one. This one takes the data and puts it into a queue. Then you have a second, Queue-triggered, Function that does not long processing and writes the result somewhere, e.g. to blob storage.

Upvotes: 5

Related Questions