0

I created an Azure function in python to insert data into SQL server. The process was taking around a minute when I was locally testing it. But when I deployed the code, I ended up receiving a 503 error as shown below.

After debugging, I realized the data was successfully persisted in the database (the whole 1 min process), but it's only the response that I get is the error.

So I created a function to just sleep for 30 seconds (after some trial and error) and render a JSON response (check below code).

I get a successful response for 29 seconds or lesser but when I make the sleep to 30 seconds, I get the 503 error

import json
import azure.functions as func
import time

def main(req: func.HttpRequest) -> func.HttpResponse:
    data = req.get_json()
    data["processed"] = True
    time.sleep(30)
    return func.HttpResponse(json.dumps(data)) 

Our services aren't available right now

We're working to restore all services as soon as possible. Please check back soon.

enter image description here

I started with a consumption plan and even changed it to Elastic Premium but the outcome did not change.

mcknz
  • 467
  • 9
  • 27
Rahul
  • 44,892
  • 25
  • 73
  • 103
  • Hello @Rahul, Could you please refer this SO THREAD for the similar discussion https://stackoverflow.com/questions/54625852/status-503-service-unavailable-azure-function – AjayKumarGhose Mar 29 '22 at 09:57
  • I have the same problem using Azure Functions with Python (but I suspect the stack does not matter). I have a while loop that waits one second and keeps polling an endpoint for a Successful status. If I set the time to anything 30 seconds or more I get the same 503 error. Still looking for a solution. – Justin Jul 21 '22 at 13:20
  • I just had a thought. Are you running on a MacBook with an M1 chip by chance? – Justin Jul 22 '22 at 05:03
  • How do you connect to SQL server? Are you using any specific library? Have you tried adjusting the command/connection timeout settings that might have default values depending on the connection you use? – FinneVirta Nov 29 '22 at 10:41

2 Answers2

1

In Azure Functions, HTTP Error 503 Service Unavailable can be caused due to few reasons like:

  • The backend server returned 503 due to a memory leak/issue in the code.
  • Platform issue due to the backend server not running/ allocated
  • Function host is down/restarting.

enter image description here

Have a look into the "Diagnose and Solve problems" blade in the Azure Function App and select the "Function app down or reporting" detector.

enter image description here

Also, Microsoft Azure Support will do the analysis to find the root cause on your function app if we send an email at azcommunity@microsoft.com with your subscription ID as well as your function app name using function logs.

0

There might be a few issues causing this so a solid 1 truth solutions seems not be fully possible. But I will list a few possible solutions.

  1. It seems to mostly be an issue when running code in the portal with Code+test. Try run the function without using the portal. (example on others issue Azure Function dies after 30 seconds and cannot run multiple invocations concurrently )

  2. Some report there might be an issue with region. (Not working in one region but after move to other region it works)

  3. Also been reports of solving this with premium plan (But looks like you tried this)

  4. Could be some other resources like a loadbalancer with lower timeouts. (Example Why does my POST request throw a 503 after 30 seconds? ). Don't know your full setup. Might be when calling the function or a request the function does.

  5. If none of the above helps it might be some python timeout like python async timeout. I am no python expert though so not fully sure here.

JohanSellberg
  • 2,423
  • 1
  • 21
  • 28