Django Redis Queue Application Failed to Respond

Hi everyone, my Django web app is down with a 503 error. I'm using Django RQ with one worker started by default as a separate service with this command /bin/bash -l -c "python3 manage.py rqworker default" which was working. The deployment of my main Django repo is successful, but I have these deploy logs:
[2023-05-31 23:25:20 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:356)
[2023-05-31 23:25:20 +0000] [356] [INFO] Worker exiting (pid: 356)
[2023-05-31 23:25:20 +0000] [399] [INFO] Booting worker with pid: 399
[2023-05-31 23:30:51 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:399)
[2023-05-31 23:30:51 +0000] [399] [INFO] Worker exiting (pid: 399)
[2023-05-31 23:30:51 +0000] [442] [INFO] Booting worker with pid: 442
[2023-05-31 23:31:24 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:442)
[2023-05-31 23:31:24 +0000] [442] [INFO] Worker exiting (pid: 442)
[2023-05-31 23:31:25 +0000] [485] [INFO] Booting worker with pid: 485
[2023-05-31 23:31:58 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:485)
[2023-05-31 23:31:58 +0000] [485] [INFO] Worker exiting (pid: 485)
[2023-05-31 23:31:59 +0000] [528] [INFO] Booting worker with pid: 528
[2023-05-31 23:25:20 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:356)
[2023-05-31 23:25:20 +0000] [356] [INFO] Worker exiting (pid: 356)
[2023-05-31 23:25:20 +0000] [399] [INFO] Booting worker with pid: 399
[2023-05-31 23:30:51 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:399)
[2023-05-31 23:30:51 +0000] [399] [INFO] Worker exiting (pid: 399)
[2023-05-31 23:30:51 +0000] [442] [INFO] Booting worker with pid: 442
[2023-05-31 23:31:24 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:442)
[2023-05-31 23:31:24 +0000] [442] [INFO] Worker exiting (pid: 442)
[2023-05-31 23:31:25 +0000] [485] [INFO] Booting worker with pid: 485
[2023-05-31 23:31:58 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:485)
[2023-05-31 23:31:58 +0000] [485] [INFO] Worker exiting (pid: 485)
[2023-05-31 23:31:59 +0000] [528] [INFO] Booting worker with pid: 528
In which a worker timeouts, exits, and then a new one boots over and over. I have the worker timeout setting at 3600 (1 hour) for my three queues. The one worker I have started by default's pid does not seem to match any of the pids in my deploy logs after checking with this code:
from django_rq import get_queue
from rq import SimpleWorker
queue = get_queue('default')
SimpleWorker.all(connection=redis_conn, queue=queue)[0].pid
from django_rq import get_queue
from rq import SimpleWorker
queue = get_queue('default')
SimpleWorker.all(connection=redis_conn, queue=queue)[0].pid
And
import os
from django_rq import get_worker
worker = get_worker('default')
pid = os.getpid()
worker_pid = worker.pid
import os
from django_rq import get_worker
worker = get_worker('default')
pid = os.getpid()
worker_pid = worker.pid
How should I continue debugging this? Project ID: 26297924-d91d-448c-b1fa-e00612d55795
50 Replies
Percy
Percy2y ago
Project ID: 26297924-d91d-448c-b1fa-e00612d55795
Brody
Brody2y ago
what protocol do rq works communicate with?
echoesembrace
echoesembraceOP2y ago
I think they use RESP (REdis Serialization Protocol)
Brody
Brody2y ago
railway only supports http services
echoesembrace
echoesembraceOP2y ago
My bad, it seems they use the Redis-based Python queuing library RQ
Brody
Brody2y ago
if its not http it wont work on railway
echoesembrace
echoesembraceOP2y ago
Thank you for letting me know. I will continuing doing research 👍 This is an explanation generated by ChatGPT and verified using phind.com (ChatGPT search engine). It aims to shed light on the workings of HTTP in the context mentioned above: Django RQ integrates with Django, which is a web framework for building web applications in Python. Django handles the HTTP part of your application, including handling incoming requests, routing, views, and generating responses. Django RQ complements Django by providing a way to offload time-consuming tasks to background workers using Redis as the message broker. When a Django view or other part of your Django application enqueues a task using Django RQ, it sends a message to Redis with the task details. The RQ workers, which are separate processes or threads, then pick up these tasks from Redis and execute them in the background. So, while Django RQ itself does not directly handle HTTP communication, it works in conjunction with Django, which takes care of the HTTP aspects of your application. Django RQ focuses on the queuing and execution of tasks in the background, leaving Django to handle the web-related functionality. Glad to learn more about this! Additionally, I would like to mention that the RQ functionality of my application was functioning properly until yesterday.
Brody
Brody2y ago
now what service are you getting a 503 from, the django app itself?
echoesembrace
echoesembraceOP2y ago
I'm getting the 503 from the dev tools console of my website. Here's the link: samplegen.com It loads for a while, then says Application failed to respond.
Brody
Brody2y ago
and that is the django app in question
echoesembrace
echoesembraceOP2y ago
Yes. Thank you for helping me investigate this!
Brody
Brody2y ago
do you have a repo for this app?
echoesembrace
echoesembraceOP2y ago
Yes I'm not sure if I can really share it though.
Brody
Brody2y ago
understandable, do you have a procfile?
echoesembrace
echoesembraceOP2y ago
No, but I have these start commands, which replaced the Procfile when I switched from Heroku: Django Web App: /bin/bash -l -c "python manage.py migrate && gunicorn config.wsgi && python3 manage.py collectstatic --no-input" Redis Worker (Same repo, separate service and different start command): /bin/bash -l -c "python3 manage.py rqworker default"
Brody
Brody2y ago
1. how are you telling railway to run these commands? 2. it doesnt look like you are starting a gunicorn server? no gunicorn server, no app
echoesembrace
echoesembraceOP2y ago
Sorry, I didn't copy the whole command when I first wrote that. Here are the full start commands: Django Web App: /bin/bash -l -c "python manage.py migrate && gunicorn config.wsgi && python3 manage.py collectstatic --no-input" Redis Worker (Same repo, separate service and different start command): /bin/bash -l -c "python3 manage.py rqworker default" However, I noticed it looks like I accidently put this in the build command: /bin/bash -l -c "python3 manage.py collectstatic --no-input" 🤦‍♂️ It's redeploying now, I'll keep you posted.
Brody
Brody2y ago
i still dont see gunicorn?
echoesembrace
echoesembraceOP2y ago
This is part of the start command for my Django web app repo: gunicorn config.wsgi The full start command is: /bin/bash -l -c "python manage.py migrate && gunicorn config.wsgi && python3 manage.py collectstatic --no-input"
Brody
Brody2y ago
the full start command does not include gunicorn though?? without seeing your repo, i am quite confused
echoesembrace
echoesembraceOP2y ago
Sorry about that, I will see what I can do about showing the repo. It looks like guincon is starting from this command: gunicorn config.wsgi Here are my deploy logs: 
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, django_rq, djstripe, generate_samples, sessions
Running migrations:
No migrations to apply.
[2023-06-01 01:49:32 +0000] [87] [INFO] Starting gunicorn 20.1.0
[2023-06-01 01:49:32 +0000] [87] [INFO] Listening at: http://0.0.0.0:8000 (87)
[2023-06-01 01:49:32 +0000] [87] [INFO] Using worker: sync
[2023-06-01 01:49:32 +0000] [88] [INFO] Booting worker with pid: 88
[2023-06-01 01:50:15 +0000] [87] [CRITICAL] WORKER TIMEOUT (pid:88)
[2023-06-01 01:50:15 +0000] [88] [INFO] Worker exiting (pid: 88)
[2023-06-01 01:50:16 +0000] [163] [INFO] Booting worker with pid: 163
[2023-06-01 01:50:49 +0000] [87] [CRITICAL] WORKER TIMEOUT (pid:163)
[2023-06-01 01:50:49 +0000] [163] [INFO] Worker exiting (pid: 163)
[2023-06-01 01:50:50 +0000] [238] [INFO] Booting worker with pid: 238
[2023-06-01 01:51:23 +0000] [87] [CRITICAL] WORKER TIMEOUT (pid:238)
[2023-06-01 01:51:23 +0000] [238] [INFO] Worker exiting (pid: 238)
[2023-06-01 01:51:23 +0000] [313] [INFO] Booting worker with pid: 313
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, django_rq, djstripe, generate_samples, sessions
Running migrations:
No migrations to apply.
[2023-06-01 01:49:32 +0000] [87] [INFO] Starting gunicorn 20.1.0
[2023-06-01 01:49:32 +0000] [87] [INFO] Listening at: http://0.0.0.0:8000 (87)
[2023-06-01 01:49:32 +0000] [87] [INFO] Using worker: sync
[2023-06-01 01:49:32 +0000] [88] [INFO] Booting worker with pid: 88
[2023-06-01 01:50:15 +0000] [87] [CRITICAL] WORKER TIMEOUT (pid:88)
[2023-06-01 01:50:15 +0000] [88] [INFO] Worker exiting (pid: 88)
[2023-06-01 01:50:16 +0000] [163] [INFO] Booting worker with pid: 163
[2023-06-01 01:50:49 +0000] [87] [CRITICAL] WORKER TIMEOUT (pid:163)
[2023-06-01 01:50:49 +0000] [163] [INFO] Worker exiting (pid: 163)
[2023-06-01 01:50:50 +0000] [238] [INFO] Booting worker with pid: 238
[2023-06-01 01:51:23 +0000] [87] [CRITICAL] WORKER TIMEOUT (pid:238)
[2023-06-01 01:51:23 +0000] [238] [INFO] Worker exiting (pid: 238)
[2023-06-01 01:51:23 +0000] [313] [INFO] Booting worker with pid: 313
Brody
Brody2y ago
do you have some sort of gunicorn config file?
echoesembrace
echoesembraceOP2y ago
No, by default Django handles gunicorn in the background and runs the web app with a command like this gunicorn project_name.wsgi using the wsgi.py file. It is possible to add a gunicorn config file to Django for further customization though. Thank you for spending the time to help! 🙂
Brody
Brody2y ago
something is telling gunicorn to listen on port 8000 show me a screenshot of your service variables please?
echoesembrace
echoesembraceOP2y ago
echoesembrace
echoesembraceOP2y ago
Brody
Brody2y ago
1. ive never seen someone with so many variables 2. what are those little numbers for? 3. try deleting the PORT variable, railway will make one for you
echoesembrace
echoesembraceOP2y ago
True, gotta appease the microservices 😂 I shared my variables because my RQ worker service needs them as it's the same repo as my website service repo running with a different start command (I may not need my RQ worker service anymore as I was successfully starting workers dynamically for a few weeks before today) I deleted the PORT variable - will keep you updated. Here are my Deploy Logs after deleting the PORT variable:
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, django_rq, djstripe, generate_samples, sessions
Running migrations:
No migrations to apply.
[2023-06-01 02:15:58 +0000] [54] [INFO] Starting gunicorn 20.1.0
[2023-06-01 02:15:58 +0000] [54] [INFO] Listening at: http://0.0.0.0:6468 (54)
[2023-06-01 02:15:58 +0000] [54] [INFO] Using worker: sync
[2023-06-01 02:15:58 +0000] [55] [INFO] Booting worker with pid: 55
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, django_rq, djstripe, generate_samples, sessions
Running migrations:
No migrations to apply.
[2023-06-01 02:15:58 +0000] [54] [INFO] Starting gunicorn 20.1.0
[2023-06-01 02:15:58 +0000] [54] [INFO] Listening at: http://0.0.0.0:6468 (54)
[2023-06-01 02:15:58 +0000] [54] [INFO] Using worker: sync
[2023-06-01 02:15:58 +0000] [55] [INFO] Booting worker with pid: 55
I got a new port number 🙂
Brody
Brody2y ago
yep now railway is randomly generating a PORT for you this is a good thing, and preferred over setting your own what is the railway domain for this service?
echoesembrace
echoesembraceOP2y ago
Thank you! Here's the railway domain: djangogeneratesamples-production.up.railway.app
Brody
Brody2y ago
just keeps loading not even a 503
echoesembrace
echoesembraceOP2y ago
Hmm, interesting I think I'm going to try rolling back to an earlier deployment that worked previously.
Brody
Brody2y ago
and im about all out of ideas wait
echoesembrace
echoesembraceOP2y ago
It works!
Brody
Brody2y ago
rollback?
echoesembrace
echoesembraceOP2y ago
I didn't rollback. Something you helped me with worked 😃
Brody
Brody2y ago
sounds tempermental do a redeploy
echoesembrace
echoesembraceOP2y ago
Okay It just finished redeploying and the website is now loading endlessly.
Brody
Brody2y ago
has the deploy logs already displayed Listening at: http://0.0.0.0:PORT
echoesembrace
echoesembraceOP2y ago
Yes, this is that line from the deploy logs: [2023-06-01 02:30:37 +0000] [54] [INFO] Listening at: http://0.0.0.0:6688 (54)
Brody
Brody2y ago
do you see worker timeouts?
echoesembrace
echoesembraceOP2y ago
Yes, these are the full deploy logs:
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, django_rq, djstripe, generate_samples, sessions
Running migrations:
No migrations to apply.
[2023-06-01 02:30:37 +0000] [54] [INFO] Starting gunicorn 20.1.0
[2023-06-01 02:30:37 +0000] [54] [INFO] Listening at: http://0.0.0.0:6688 (54)
[2023-06-01 02:30:37 +0000] [54] [INFO] Using worker: sync
[2023-06-01 02:30:37 +0000] [55] [INFO] Booting worker with pid: 55
[2023-06-01 02:31:10 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:55)
[2023-06-01 02:31:10 +0000] [55] [INFO] Worker exiting (pid: 55)
[2023-06-01 02:31:11 +0000] [98] [INFO] Booting worker with pid: 98
[2023-06-01 02:31:44 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:98)
[2023-06-01 02:31:44 +0000] [98] [INFO] Worker exiting (pid: 98)
[2023-06-01 02:31:44 +0000] [141] [INFO] Booting worker with pid: 141
[2023-06-01 02:32:18 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:141)
[2023-06-01 02:32:18 +0000] [141] [INFO] Worker exiting (pid: 141)
[2023-06-01 02:32:18 +0000] [184] [INFO] Booting worker with pid: 184
[2023-06-01 02:32:51 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:184)
[2023-06-01 02:32:51 +0000] [184] [INFO] Worker exiting (pid: 184)
[2023-06-01 02:32:52 +0000] [227] [INFO] Booting worker with pid: 227
[2023-06-01 02:33:25 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:227)
[2023-06-01 02:33:25 +0000] [227] [INFO] Worker exiting (pid: 227)
[2023-06-01 02:33:26 +0000] [270] [INFO] Booting worker with pid: 270
[2023-06-01 02:33:59 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:270)
[2023-06-01 02:33:59 +0000] [270] [INFO] Worker exiting (pid: 270)
[2023-06-01 02:34:00 +0000] [313] [INFO] Booting worker with pid: 313
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, django_rq, djstripe, generate_samples, sessions
Running migrations:
No migrations to apply.
[2023-06-01 02:30:37 +0000] [54] [INFO] Starting gunicorn 20.1.0
[2023-06-01 02:30:37 +0000] [54] [INFO] Listening at: http://0.0.0.0:6688 (54)
[2023-06-01 02:30:37 +0000] [54] [INFO] Using worker: sync
[2023-06-01 02:30:37 +0000] [55] [INFO] Booting worker with pid: 55
[2023-06-01 02:31:10 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:55)
[2023-06-01 02:31:10 +0000] [55] [INFO] Worker exiting (pid: 55)
[2023-06-01 02:31:11 +0000] [98] [INFO] Booting worker with pid: 98
[2023-06-01 02:31:44 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:98)
[2023-06-01 02:31:44 +0000] [98] [INFO] Worker exiting (pid: 98)
[2023-06-01 02:31:44 +0000] [141] [INFO] Booting worker with pid: 141
[2023-06-01 02:32:18 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:141)
[2023-06-01 02:32:18 +0000] [141] [INFO] Worker exiting (pid: 141)
[2023-06-01 02:32:18 +0000] [184] [INFO] Booting worker with pid: 184
[2023-06-01 02:32:51 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:184)
[2023-06-01 02:32:51 +0000] [184] [INFO] Worker exiting (pid: 184)
[2023-06-01 02:32:52 +0000] [227] [INFO] Booting worker with pid: 227
[2023-06-01 02:33:25 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:227)
[2023-06-01 02:33:25 +0000] [227] [INFO] Worker exiting (pid: 227)
[2023-06-01 02:33:26 +0000] [270] [INFO] Booting worker with pid: 270
[2023-06-01 02:33:59 +0000] [54] [CRITICAL] WORKER TIMEOUT (pid:270)
[2023-06-01 02:33:59 +0000] [270] [INFO] Worker exiting (pid: 270)
[2023-06-01 02:34:00 +0000] [313] [INFO] Booting worker with pid: 313
Brody
Brody2y ago
okay so gunicorn is starting correctly, but your app itself isnt responding
echoesembrace
echoesembraceOP2y ago
Yes, I don't know why it just finished loading 🤔
Brody
Brody2y ago
sounds like you have some debuging to do since this is an issue with your code, theres not much more i can do for you unfortunately
echoesembrace
echoesembraceOP2y ago
No problem, you've been amazing! Thank you so much! I'm glad we could narrow it down 😃
Brody
Brody2y ago
glad i could help somewhat! id be very intrested to know what the cause was once you nail this issue down
echoesembrace
echoesembraceOP2y ago
Definitely, I'll keep you updated! Learning and using Redis queues for this project has been interesting.
Brody
Brody2y ago
feel free to ping when solved 🙂
echoesembrace
echoesembraceOP2y ago
Okay awesome 🙂
Want results from more Discord servers?
Add your server