I am currently trying to host a Django application on Railway, but I am facing an issue in the Gunicorn server which keeps getting stuck at [DEBUG] Closing Connection.
status, below are my logs.
gunicorn.conf.py
# Non logging stuff
bind = "0.0.0.0:8000"
workers = 3
# Access log - records incoming HTTP requests
accesslog = "-"
# Error log - records Gunicorn server goings-on
errorlog = "-"
# Whether to send Django output to the error log
capture_output = True
# How verbose the Gunicorn error logs should be
loglevel = "debug"
# Increase the timeout for each worker to 90 seconds
timeout = 90
Railway Deployment Logs
2023-05-04 08:54:18 [1] [INFO] Starting gunicorn 18.0
2023-05-04 08:54:18 [1] [DEBUG] Arbiter booted
2023-05-04 08:54:18 [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
2023-05-04 08:54:18 [1] [INFO] Using worker: sync
/root/.nix-profile/lib/python3.10/os.py:1030: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
return io.open(fd, mode, buffering, encoding, *args, **kwargs)
2023-05-04 08:54:18 [9] [INFO] Booting worker with pid: 9
2023-05-04 08:54:18 [10] [INFO] Booting worker with pid: 10
2023-05-04 08:54:18 [11] [INFO] Booting worker with pid: 11
2023-05-04 08:58:19 [9] [DEBUG] Closing connection.
2023-05-04 09:03:28 [10] [DEBUG] Closing connection.
2023-05-04 09:08:31 [9] [DEBUG] Closing connection.
requirements.txt
asgiref==3.6.0
beautifulsoup4==4.12.2
cachetools==5.3.0
certifi==2022.9.24
charset-normalizer==2.1.1
Django==4.0
django-cors-headers==3.13.0
django-crispy-forms==1.14.0
django-environ==0.10.0
djangorestframework==3.14.0
gunicorn==18.0.0 # Purposefully downgraded
idna==3.4
Pillow==9.3.0
proto-plus==1.22.2
protobuf==4.22.3
# psycopg==3.1.8
# psycopg-binary==3.1.8
psycopg2-binary==2.9.6
pyasn1==0.5.0
pyasn1-modules==0.3.0
python-dotenv==1.0.0
pytz==2022.6
reportlab==3.6.12
requests==2.28.1
rsa==4.9
six==1.16.0
soupsieve==2.4.1
sqlparse==0.4.3
typing_extensions==4.5.0
tzdata==2022.7
urllib3==1.26.13
waitress==2.1.2
whitenoise==6.4.0
Procfile
web: gunicorn my-django-app.wsgi:application
The odd part is that sometimes the webapp works fine and then suddenly crashes in the production, I have already tried running the gunicorn sever locally with the remote database, it works fine locally.
Here I have purposefully downgraded the gunicorn
and Django
versions since a issue said the [DEBUG] Closing Connection.
is caused in gunicorn 20 and Django 4.2 due to internal dependency conflicts. Issue Reference
I have tried to change the server from gunicorn
to waitress
or even the bare python manage.py runserver
, but none of the solutions have worked so far.