Issue with redis connection and celery task running.
leolmz59
HOBBYOP

a year ago

Hello,

In my django app I'm using redis to run a task using celery worker and beater.

After deploying I get thses messages in the deploy logs:

Starting Container

Mar 26 10:58:09

2025-03-26 09:58:09,465 - comparaplan.celery - INFO - Successfully validated Redis URL: redis://default:mypassword@redis.railway.internal:6379

Mar 26 10:58:09

2025-03-26 09:58:09,468 - comparaplan.celery - INFO - Periodic tasks configured successfully

Mar 26 10:58:09

2025-03-26 09:58:09,584 - comparaplan.celery - INFO - white_check_mark emoji Redis Connection Successful (Attempt 1)

Mar 26 10:58:11

Operations to perform:

Mar 26 10:58:11

Apply all migrations: admin, auth, contact, contenttypes, django_celery_beat, mobile_subscriptions, prospectAlert, sessions

Mar 26 10:58:11

Running migrations:

Mar 26 10:58:11

No migrations to apply.

Mar 26 10:58:12

[2025-03-26 09:58:12 +0000] [1] [INFO] Starting gunicorn 23.0.0

Mar 26 10:58:12

[2025-03-26 09:58:12 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)

Mar 26 10:58:12

[2025-03-26 09:58:12 +0000] [1] [INFO] Using worker: sync

Mar 26 10:58:12

[2025-03-26 09:58:12 +0000] [5] [INFO] Booting worker with pid: 5

Mar 26 10:58:13

2025-03-26 09:58:13,269 - comparaplan.celery - INFO - Successfully validated Redis URL: redis://default:mypassword@redis.railway.internal:6379

Mar 26 10:58:13

2025-03-26 09:58:13,277 - comparaplan.celery - INFO - Periodic tasks configured successfully

Mar 26 10:58:13

2025-03-26 09:58:13,498 - comparaplan.celery - INFO - white_check_mark emoji Redis Connection Successful (Attempt 1)

Until now it looks good.

I'm trigerring the celery task via a post request:

After loading new logs appear:

[ERROR] 2025-03-26 10:09:19,758 redis - Connection to Redis lost: Retry (0/20) now.

Mar 26 11:09:39

[CRITICAL] 2025-03-26 10:09:39,859 redis -

Mar 26 11:09:39

Retry limit exceeded while trying to reconnect to the Celery redis result store backend. The Celery application must be restarted.

Weird cause the first logs indicated that the connection was done.

I'm 100% sure I used the right REDIS_URL already.

My Procfile has the following content:
web: python manage.py migrate && gunicorn comparaplan.wsgi --bind 0.0.0.0:$PORT

worker: celery -A comparaplan worker --loglevel=info

beat: celery -A comparaplan beat --loglevel=info

Closed

5 Replies

leolmz59
HOBBYOP

a year ago

Btw the script works fine in local ..

Starting Container

Mar 26 16:21:55

REDIS_URL = redis://default:mypassword@redis.railway.internal:6379

Mar 26 16:21:55

2025-03-26 15:21:54,295 - comparaplan.celery - INFO - Periodic tasks configured successfully

Mar 26 16:21:55

2025-03-26 15:21:54,455 - comparaplan.celery - INFO - white_check_mark emoji Redis Connection Successful (Attempt 1)

Mar 26 16:21:55

2025-03-26 15:21:54,460 - comparaplan.settings - INFO - Attempting to connect to Redis URL: redis://de...ernal:6379

Mar 26 16:21:55

2025-03-26 15:21:54,537 - comparaplan.settings - INFO - Redis connection successful. Ping response: True

Mar 26 16:21:55

REDIS_URL = redis://default:mypassword@redis.railway.internal:6379

Mar 26 16:21:55

Current working directory: /app

Mar 26 16:21:55

Operations to perform:

Mar 26 16:21:55

Apply all migrations: admin, auth, contact, contenttypes, django_celery_beat, mobile_subscriptions, prospectAlert, sessions

Mar 26 16:21:55

Running migrations:

Mar 26 16:21:55

No migrations to apply.

Mar 26 16:21:57

[2025-03-26 15:21:57 +0000] [1] [INFO] Starting gunicorn 23.0.0

Mar 26 16:21:57

[2025-03-26 15:21:57 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)

Mar 26 16:21:57

[2025-03-26 15:21:57 +0000] [1] [INFO] Using worker: sync

Mar 26 16:21:57

[2025-03-26 15:21:57 +0000] [5] [INFO] Booting worker with pid: 5

Mar 26 16:21:57

REDIS_URL = redis://default:mypassword@redis.railway.internal:6379

Mar 26 16:21:57

2025-03-26 15:21:57,507 - comparaplan.celery - INFO - Periodic tasks configured successfully

Mar 26 16:21:57

2025-03-26 15:21:57,585 - comparaplan.celery - INFO - white_check_mark emoji Redis Connection Successful (Attempt 1)

Mar 26 16:21:57

2025-03-26 15:21:57,693 - comparaplan.settings - INFO - Attempting to connect to Redis URL: redis://de...ernal:6379

Mar 26 16:21:57

2025-03-26 15:21:57,705 - comparaplan.settings - INFO - Redis connection successful. Ping response: True

Mar 26 16:22:17

REDIS_URL = redis://default:mypassword@redis.railway.internal:6379

Mar 26 16:22:17

Current working directory: /app

Mar 26 16:22:17

[INFO] 2025-03-26 15:22:09,094 views - Attempting to start scraping task

Mar 26 16:22:17

[ERROR] 2025-03-26 15:22:09,230 redis - Connection to Redis lost: Retry (0/20) now.

Mar 26 16:22:17

[ERROR] 2025-03-26 15:22:09,302 redis - Connection to Redis lost: Retry (1/20) in 1.00 second.

Mar 26 16:22:17

[ERROR] 2025-03-26 15:22:11,426 redis - Connection to Redis lost: Retry (3/20) in 1.00 second.

Mar 26 16:22:17

[ERROR] 2025-03-26 15:22:12,443 redis - Connection to Redis lost: Retry (4/20) in 1.00 second.

Mar 26 16:22:17

[ERROR] 2025-03-26 15:22:14,563 redis - Connection to Redis lost: Retry (6/20) in 1.00 second.

Mar 26 16:22:17

[ERROR] 2025-03-26 15:22:16,664 redis - Connection to Redis lost: Retry (8/20) in 1.00 second.

Mar 26 16:22:17

[ERROR] 2025-03-26 15:22:17,701 redis - Connection to Redis lost: Retry (9/20) in 1.00 second.

Mar 26 16:22:18

[ERROR] 2025-03-26 15:22:18,707 redis - Connection to Redis lost: Retry (10/20) in 1.00 second.

Mar 26 16:22:19

[ERROR] 2025-03-26 15:22:19,753 redis - Connection to Redis lost: Retry (11/20) in 1.00 second.

Mar 26 16:22:20

[ERROR] 2025-03-26 15:22:20,755 redis - Connection to Redis lost: Retry (12/20) in 1.00 second.

Mar 26 16:22:21

[ERROR] 2025-03-26 15:22:21,795 redis - Connection to Redis lost: Retry (13/20) in 1.00 second.

Mar 26 16:22:22

[ERROR] 2025-03-26 15:22:22,800 redis - Connection to Redis lost: Retry (14/20) in 1.00 second.

Mar 26 16:22:23

[ERROR] 2025-03-26 15:22:23,843 redis - Connection to Redis lost: Retry (15/20) in 1.00 second.

Mar 26 16:22:24

[ERROR] 2025-03-26 15:22:24,846 redis - Connection to Redis lost: Retry (16/20) in 1.00 second.

Mar 26 16:22:25

[ERROR] 2025-03-26 15:22:25,874 redis - Connection to Redis lost: Retry (17/20) in 1.00 second.

Mar 26 16:22:26

[ERROR] 2025-03-26 15:22:26,876 redis - Connection to Redis lost: Retry (18/20) in 1.00 second.

Mar 26 16:22:27

[ERROR] 2025-03-26 15:22:27,899 redis - Connection to Redis lost: Retry (19/20) in 1.00 second.

Mar 26 16:22:28

[CRITICAL] 2025-03-26 15:22:28,901 redis -

Mar 26 16:22:28

Retry limit exceeded while trying to reconnect to the Celery redis result store backend. The Celery application must be restarted.

What could be the issue ? The initiale connection to redis is good and then when I triger my task it lost the connection


chandrika
EMPLOYEE

a year ago

If you're using ioredis, ensure the family option is set to 0 in your connection settings to allow dual-stack (IPv4 and IPv6) lookups. This can help if the connection issue is DNS-related. You can see more about handling this type of issue here.


Status changed to Awaiting User Response Railway 12 months ago


chandrika

If you're using ioredis, ensure the family option is set to 0 in your connection settings to allow dual-stack (IPv4 and IPv6) lookups. This can help if the connection issue is DNS-related. You can see more about handling this type of issue here.

leolmz59
HOBBYOP

a year ago

Hi Chandrika, Thanks for your answer. I'm not using ioredis. I'm using django for this project


Status changed to Awaiting Railway Response Railway 12 months ago


leolmz59
HOBBYOP

a year ago

The problem seems to be "{"status": "error", "message": "Failed to start task: invalid username-password pair or user is disabled."}
However I don't understand because my REDIS_URL containing the username and the password match the one from the redis variable on Raiwail


chandrika
EMPLOYEE

a year ago

Hey there, will close this one out and chat in the other thread we have!


Status changed to Awaiting User Response Railway 12 months ago


Status changed to Closed chandrika 12 months ago


Loading...