Python "Celery worker cannot connect to broker" in CI
A Celery worker that cannot reach its broker logs "consumer: Cannot connect to ..." and retries. In CI tests this stalls or fails when the broker (Redis or RabbitMQ) service is not running or the broker URL is wrong.
What this error means
CI shows "consumer: Cannot connect to redis://localhost:6379//: Error connecting to Redis." repeating, and Celery-backed tests time out or fail.
python
[ERROR/MainProcess] consumer: Cannot connect to redis://localhost:6379//: Error connecting to Redis.
Trying again in 2.00 seconds...Common causes
The broker service is not running in CI
No Redis/RabbitMQ service was started, or it was not ready when the worker booted.
A broker URL that is correct locally but wrong in CI
localhost vs a service hostname mismatch in the CI network topology.
How to fix it
Run the broker as a service and use eager mode where possible
- Start the broker service in the job and set CELERY_BROKER_URL to match.
- For unit tests, set task_always_eager=True so tasks run inline without a broker.
- Gate integration tests on a broker readiness check.
Python
# unit tests: run tasks inline, no broker needed
app.conf.task_always_eager = True
app.conf.task_eager_propagates = TrueHow to prevent it
- On Latchkey managed runners, transient broker connection failures during startup are auto-retried.
- Use task_always_eager for unit tests.
- Gate Celery integration tests on broker readiness.
Related guides
Python "redis.exceptions.ConnectionError" in CIFix "redis.exceptions.ConnectionError: Error connecting to Redis" in CI - the redis-py client could not reach…
Python "urllib3 NewConnectionError" in CIFix "urllib3.exceptions.NewConnectionError: Failed to establish a new connection" in CI - urllib3 could not o…
Python "moto mock not patching boto3" in CIFix moto mocks that do not patch boto3 in CI - real AWS calls leak through because the client was created out…