Azure Flask Web App Fails During Deployment (504 Gateway Timeout Error)

Ahad Anjum 60 Reputation points
2024-04-01T16:03:50.2766667+00:00

Screenshot 2024-04-01 194733

Currently this is what my deployed web app looks like when I open the link.

Screenshot 2024-03-29 161435

When I attached a parameter (necessary for how the app functions) I got a 504.0 Gateway Timeout Error. The parameter is used in regard to an SQL Server Database table query. When the app doesn't have the param it opens up and renders a different html page.

The container error looks like this:

Screenshot 2024-04-01 194937

On my GitHub, the app says it is successfully deployed. The app is a Langchain based Flask application. At the start of the application, the web app is meant to connect to my SQL server, using the parameter, and grab data from some tables and turn them into panda data frames in Python. Locally, this process runs perfectly, however it does not work in the deployment URL.

The code I used in my python flask app is:

app.run(host="0.0.0.0", port="8000")


And in my startup.txt file I use:

gunicorn --bind=0.0.0.0 --timeout 600 app:app

Both these commands are correct my Flask app is called app and is in app.py. I have checked to make sure all environment variables are correct and exist when I check the SSH. Furthermore, I have env WEBSITES_PORT set to 8000.

Previously I was having an issue connecting to my SQL Server, but I received help and set up the connection to the server using VNet integration. I no longer get error messages pertaining to the server but the timeout in regard to the container is persistent. I even increased the timeout time to be 600 seconds instead of 230 and it still failed. I am not using dockers in any way in my project either.

I am stuck and not sure how to get rid of this error. Again, the web app works extremely well locally so I know this must be a deployment/server issue which is not my forte. Also, In the application logs, there are no erors, the web app is listening on port 0.0.0.0.8000 and reading my startup.txt file. If there's any other information, I can provide for clarity, please let me know! I would really appreciate any and all help!

Edit: Using the diagnostic helps in the web app it recommended I take a look at this page: https://azureossd.github.io/2023/02/15/Whats-the-difference-between-PORT-and-WEBSITES_PORT/index.html

However, I have set the port to be 8000 and I still have this issue. Should I maybe use PORT instead? I also don't have any dockers files or anything related in this project so not sure if Dockers plays a role in fixing the 504 Gateway Timeout Error.

This is from the log stream that is in the picture below. It seems as if the web app is pinging the port that is used for SQL Server: 

2024-03-31T23:59:14.282Z ERROR - Container remi2_1_1e46950a for site remi2 did not start within expected time limit. Elapsed time = 601.0096697 sec 2024-03-31T23:59:14.291Z ERROR - Container remi2_1_1e46950a didn't respond to HTTP pings on port: 1433, failing site start. See container logs for debugging.

Here is the diagnostic report:
Screenshot 2024-04-01 221513

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,897 questions
0 comments No comments
{count} votes

Accepted answer
  1. brtrach-MSFT 15,251 Reputation points Microsoft Employee
    2024-04-02T00:46:33.4433333+00:00

    @Ahad Anjum Based on the information you provided, it looks like the container for your site is not starting within the expected time limit and the app is not responding to health checks.

    One possible reason for this issue could be that the app is trying to connect to the SQL Server using the wrong port. The error message you provided indicates that the container didn't respond to HTTP pings on port 1433. This port is typically used for SQL Server, so it's possible that the app is trying to connect to the SQL Server using this port instead of the correct port.

    You mentioned that you have set the port to be 8000, but it's still not working. Have you tried using the PORT environment variable instead of WEBSITES_PORT? According to the link you provided, WEBSITES_PORT is used for internal communication between the Azure App Service and the container, while PORT is used by the container to listen for incoming requests.


0 additional answers

Sort by: Most helpful