0

I wrote an azure function with python that do some data processing, when I test on large dataset (150 lines), chrome raise a 502 http error : (tested the azure function on 10 lines and everything was ok)

502 error

I think the problem is that chrome browser wait for so long and when no response coming from azure function it automatically raises 502 error. I checked that the logic function is executed till the end but I don't get my json response when code is completed. Here is my http response I should get

return func.HttpResponse(json.dumps({"file" : file.name.split('/')[2]}),
                                mimetype="application/json",)

expected output :

{"file": "filename.json"}

In production I have to process more then 1500 lines, and within 150 lines the azure function take about 2 minutes to complete.

How to force chrome client or any client who hit the url of my azure function to wait to complete? is there any workaround pls?

marOne
  • 129
  • 2
  • 13
  • The result of waiting for a couple of minutes should not be a 502 error. That would imply there is something in your code that is resulting in an error. As a simple test, I created an Azure Function that simply contains `await Task.Delay(new TimeSpan(0, 2, 30));` followed by a simple success message. Testing in Chrome, Edge, and Postman, I get a response back after the 00:02:30 delay. This is probably not related to your Azure Function taking more than two minutes. – Kyle Bunting Nov 30 '20 at 19:24
  • Thanks @KyleBunting for your comment, I said to myself the same thing, but when I tested my code for only 3 lines everything is working as expected, I changed the value of timeout in postman to 9999999 ms and got the response at the end, maybe we can't force it by code :( – marOne Nov 30 '20 at 21:45
  • Hi, may I know if the solution provided below helps your problem. If your problem was solved, could you please mark it as "accepted", thanks in advance. – Hury Shen Dec 03 '20 at 07:18

1 Answers1

0

For this problem, we are not client so we can't determine timeout value of client.

For your problem of force chrome client to wait the function complete, I'm afraid we can't do this setting. You can refer to this post (also shown as below screenshot). enter image description here According to the screenshot above, we can see chrome can't change the timeout setting and we can change it in other browsers.

If the client do not use browser but use code(such as .net) to request the function, the code should be like:

HttpClient httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromMinutes(10);
Hury Shen
  • 14,948
  • 1
  • 9
  • 18
  • Thank you for your answer, your code is in .net and I’m using azure function in python, how can I implement it in my python code? Didn’t find a doc ! – marOne Dec 03 '20 at 12:24
  • I tested my azure function in azure data factory then I counter the same problem, the activity just return ‘fail’ when no response returned within 1 minute. So your code above is applied on every type of client or just browsers? – marOne Dec 03 '20 at 12:26
  • @marOne As I mentioned in my answer, it just a sample for the client use .net to request your function. If the client use python to request your function, the code should be like [this](https://i.stack.imgur.com/Gbmtf.png). – Hury Shen Dec 04 '20 at 03:01
  • My client is not python, it's the azure function written in python, what I understand is to add `timeout` param in my `main` in my azure function, here is what it look like : ` ... try: req_body = req.get_json() logging.info('We got json') except ValueError: return func.HttpResponse(json.dumps({"error" : "Perhaps not a valid json"}), mimetype="application/json",) ... ` and I'm sending the request via an activity in azure data factory which react as a client ! – marOne Dec 04 '20 at 17:22