Nginx Container Becomes Unresponsive After Esmerald Deployment: Debugging SWAG + Esmerald Deployment Issue #375
Replies: 7 comments 42 replies
-
@sanket-parte It seems like you might have some resources issues or some issues with configurations. You example is not enough to understand the cause but have a look at this It's public archive but there also has some nginx, Gunicorn, docker and uvicorn configurations that you can probably check and use? |
Beta Was this translation helpful? Give feedback.
-
Ohhhh wait. @sanket-parte that script to start uvicorn it won't work properly in n production. They even said that you should use that for development only (https://github.com/dymmond/esmerald/blob/main/esmerald/conf/directives/project_template/project_name/serve.py-tpl#L5). The URL I sent before has an example of configurations how to start a server for production using also supervisor. https://github.com/dymmond/esmerald-tortoise-nginx-gunicorn-supervisor Have a look and see how we did. Also in the docs of Esmerald we have an example as well |
Beta Was this translation helpful? Give feedback.
-
Hey @tarsil, Thank you very much! for your quick response. I will try this configurations. |
Beta Was this translation helpful? Give feedback.
-
Hey @tarsil , I’ve tried configuring Gunicorn using the setup provided in this URL that you shared, but the same issue persists. Here are the configurations we're using: Gunicorn Configuration Script::import json
import multiprocessing
import os
proc_name = os.getenv("GUNIICORN_PROCESS_NAME", "gunicorn")
project_dir = os.getenv("PROJECT_DIR", "/app")
chdir = os.path.join(project_dir, "/project")
pidfile = os.getenv("GUNIICORN_PIDFILE", None)
host = os.getenv("GUNIICORN_HOST", "0.0.0.0")
port = os.getenv("GUNIICORN_PORT", "8000")
keepalive = int(os.getenv("GUNIICORN_KEEP_ALIVE", "5"))
timeout = int(os.getenv("GUNIICORN_TIMEOUT", "120"))
graceful_timeout = int(os.getenv("GUNIICORN_GRACEFUL_TIMEOUT", "120"))
forwarded_allow_ips = os.getenv("GUNIICORN_FORWARD_ALLOW_IPS", "*")
worker_class = os.getenv("GUNIICORN_WORKER_CLASS", "uvicorn.workers.UvicornWorker")
user = os.getenv("USER", "project_user")
group = os.getenv("GROUP", "project_user")
workers_per_core = float(os.getenv("GUNIICORN_WORKERS_PER_CORE", "1"))
bind = os.getenv("BIND", f"{host}:{port}")
# Logs configurations
loglevel = os.getenv("GUNIICORN_LOGLEVEL", "info")
logger_path = os.getenv("LOGS_DIR")
accesslog = "-"
errorlog = os.path.join(logger_path, "gunicorn-error.log")
web_concurrency = None
max_workers = os.getenv("GUNIICORN_MAX_WORKERS")
use_max_workers = None
if max_workers:
use_max_workers = int(max_workers)
concurr = os.getenv("GUNIICORN_WEB_CONCURRENCY")
cores = multiprocessing.cpu_count()
default_web_concurrency = float(workers_per_core) * cores
if concurr:
web_concurrency = int(concurr)
assert web_concurrency > 0
else:
web_concurrency = max(int(default_web_concurrency), 2)
if use_max_workers:
web_concurrency = min(web_concurrency, use_max_workers) Supervisord Configuration FIle:[program:gunicorn]
command = gunicorn main:app -c /app/conf/gunicorn-conf.py
user = project_user
numprocs = 1
priority = 14
startsecs = 10
autostart = true
autorestart = true
process_name = gunicorn-%(process_num)d
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes = 0
redirect_stderr = true Command to Start Supervisord:/usr/bin/supervisord Could you please assist us in debugging this issue? |
Beta Was this translation helpful? Give feedback.
-
Yes, all these configurations are correct. I am able to run the application, and it is accessible from the browser. However, after some time, my Nginx container becomes unresponsive, leading to a gateway timeout error in the browser. Following are the logs after running the application using above configurations: |
Beta Was this translation helpful? Give feedback.
-
This is very odd. Do you use any "uvicorn.run()"? You should not do that |
Beta Was this translation helpful? Give feedback.
-
Can you try to replicate the application using local redis or mongodb on you dev environment. And add logs to check if the redis or mongodb is connecting then we will know when to do next |
Beta Was this translation helpful? Give feedback.
-
Hi Everyone,
We have deployed the Esmerald application using Docker, and it's being served through nginx configured in the linuxserver/swag docker container. We’re encountering an issue where, after starting the Esmerald application, the server becomes unresponsive after some time. Specifically, the swag (nginx) container stops responding, leading to request timeout errors when accessing APIs.
Here are the current configurations:
Uvicorn Script
We are using the following uvicorn script to start the Esmerald application:
Nginx Configuration
Here is the nginx configuration:
Can anyone suggest how to debug this issue?
Beta Was this translation helpful? Give feedback.
All reactions