0

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?

Devesh Sharma
  • 949
  • 11
  • 14
  • choose a bigger timeout when you call the function? https://requests.readthedocs.io/en/latest/user/quickstart/#timeouts – 4c74356b41 Feb 04 '20 at 17:39
  • @4c74356b41 I have already increased the timeout of the Azure function. If the timeout of the function would have less, it would not process the load on server also, which in contrast it does. I face 504 timeout on client side. Server side process completes itself. – Devesh Sharma Feb 04 '20 at 17:41
  • thats what I'm saying. increase the timeout on the client – 4c74356b41 Feb 04 '20 at 17:48
  • @4c74356b41 I have tried using {'Keep-Alive': 'timeout=720000'} in the headers as well, but no luck – Devesh Sharma Feb 04 '20 at 17:53
  • are you aware of the timeout limits in Consumption plan? https://learn.microsoft.com/en-us/azure/azure-functions/functions-scale#timeout Long running processes are not really suited for running in consumption plan – silent Feb 04 '20 at 18:15
  • @silent I am not using a consumption plan. I am using App Service plan for my azure function. – Devesh Sharma Feb 04 '20 at 18:53
  • well ok. But this still applies: "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." – silent Feb 04 '20 at 19:05
  • see my answer below – silent Feb 04 '20 at 19:09
  • Be mindful of other people's sockets if you don't care about your own. Use a [`202 Accepted`](https://httpstatuses.com/202) pattern with a Location header that points to the result URL in the future and a [`Retry-after`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header with a hint. – evilSnobu Feb 04 '20 at 20:11

2 Answers2

4

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.

silent
  • 14,494
  • 4
  • 46
  • 86
  • Durable azure functions are not available in python I guess. If yes, can you please me the sample git repo. – Devesh Sharma Feb 04 '20 at 19:21
  • No, they are not unfortunately. Otherwise I would have suggested that path ;) – silent Feb 04 '20 at 19:22
  • would you mind to explain your down vote? This does answer the question why the 504 gets thrown – silent Feb 04 '20 at 19:48
  • explaining y does is not an answer to my question. What you told is something which I have already explored. – Devesh Sharma Feb 04 '20 at 19:51
  • 1
    a) you did not mention that you have already tried implementing something using queues. b) if you would have, why would it not solve your issue? – silent Feb 04 '20 at 19:52
0

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.

Community
  • 1
  • 1
Devesh Sharma
  • 949
  • 11
  • 14