Dash app down , 502 error randomly

I’ve deployed a dash app on one of my corporate servers (linux ) and i have users complaining from application being down for no reason. (502 error) and after i manually restart the app it works . Locally everything seems to be OK

Anyone has an idea about this issue ? maybe a tiemout from dash ?

THANKS

Hello @Lo96,

If you dont, you should use nginx and supervisor. Then I would also highly recommend using the on_error for the app and have it send you notifications if errors happen. This will keep you alerted of issues in the code that you havent accounted for, as well as keep the app running continuously.

Hi, thanks for your reply.

can you explain why is this happening ? how nginx use will resolve the issue ? many thanks

Nginx is a reverse proxy which allows the app to be run by gunicorn with multiple apps running. This is why its important to be stateless.

Technically, you could just run the app with gunicorn and a supervisor and just have people punch in the port of :8000 or whatever port you setup with gunicorn. Nginx just allows you to use the http :80 or https :443 ports and route traffic to any internal port you want.

The biggest thing is supervisor, this allows applications to restart automatically if they fail for whatever reason.

thanks for the info. after some googling i found that nohup could be interresting to prevent the process from dying. So i set up nohup on my app.py. let’s see if this will solve my issue at least on the short term. Will do more research on nginx & supervisor

Looks like nohup just keeps it running after closing the terminal.

This wont work if your app is actually crashing. Also, on a server restart you’d have to run the command again. Supervisor would take care of all these scenarios for you. :slight_smile:

do you have any recommendations for starting with Supervisor? I’m looking at the offcial documentation here : Introduction — Supervisor 4.2.5 documentation . Do you see other ressources/tips that will get me rapidly understand and deploy the tool ? many thanks

Hello @Lo96,

I feel like supervisor is fairly straightforward with using. However, the trickiest part is getting the gunicorn string to work. But you should be able to get that working fairly straightforward.

Here is one that I use at work:

[program:main]
command={path to your venv}/bin/gunicorn -b 0.0.0.0:8000 -w {how many works 2*cores+1} --timeout 1200 "app:server"
autostart=true
autorestart=true
stdout_logfile=/home/var/logs/main.out.log
stderr_logfile=/home/var/logs/main.err.log

Then you can use commands to control when starting or stopping the program main

The logs are helpful for keeping up with things that have crashed, or just outputs from the system.