Repository navigation
Description
We are using Django Rest Framework with MongoEngine, Redis, Celery and Kombu, and we are getting the following error in our logs:
`[2017-03-22 06:26:01,702: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer/consumer.py", line 318, in start
blueprint.start(self)
File "/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py", line 119, in start
step.start(parent)
File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer/consumer.py", line 594, in start
c.loop(*c.loop_args())
File "/usr/local/lib/python2.7/dist-packages/celery/worker/loops.py", line 88, in asynloop
next(loop)
File "/usr/local/lib/python2.7/dist-packages/kombu/async/hub.py", line 345, in create_loop
cb(*cbargs)
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/redis.py", line 1039, in on_readable
self.cycle.on_readable(fileno)
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/redis.py", line 337, in on_readable
chan.handlerstype
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/redis.py", line 667, in _receive
ret.append(self._receive_one(c))
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/redis.py", line 678, in _receive_one
response = c.parse_response()
File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 2183, in parse_response
return self._execute(connection, connection.read_response)
File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 2176, in _execute
return command(*args)
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 577, in read_response
response = self._parser.read_response()
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 238, in read_response
response = self._buffer.readline()
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 168, in readline
self._read_from_socket()
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 143, in _read_from_socket
(e.args,))
ConnectionError: Error while reading from socket: ('Connection closed by server.',)
[2017-03-22 06:26:01,868: INFO/MainProcess] Connected to redis://:******************************/1
Versions used
python==2.7.12
redis==3.2.3
kombu==4.0.2
Django==1.10.3
celery==4.0.2
amqp==2.1.1
billiard==3.5.0.2
pytz==2016.7
Django==1.10.3o
We have HaProxy infront of Redis cluster and connections, everything else work without any issues. Could you please help us trouble shoot this error ?
Or guide on what to look for and where to look for , etc ?
We really appreciate your help,
Thanks,
Darsana
Activity
jpatel3 commentedon Mar 27, 2017
@dharanpdarsana Do you have redis running? Here is how you can validate -
dharanpdarsana commentedon Mar 28, 2017
@jpatel3 redis is running and 90% of the connections are going through without any issue
richmondwang commentedon May 22, 2017
I am also (suddenly) experiencing a broken pipe error.
It was working perfectly fine before. I've forgotten what I have installed or did to trigger this.
$ pip freeze
Kurara commentedon Jun 6, 2017
I have the same problem and I'm using the same versions and I can't find a solution :(
pengye91 commentedon Jun 19, 2017
I am using kombu and running into the same situation, I'm not sure but I think maybe it's an issue working with haproxy.
When connected to haproxy which routes connections to several rabbitmq nodes, both producers and consumers have the same "connection to broker lost" issue, but when directly connected to a rabbitmq node, the issue never occurs.
mistercrunch commentedon Jun 21, 2017
Also seeing this, and also behind haproxy:
Downgrading celery to 3.1.25
Surgo commentedon Jun 28, 2017
Maybe it's happened SQS brokers too:
miljevic commentedon Aug 10, 2017
The same problem here, Celery with RabbitMQ and eventlet.
amqp==2.2.1
billiard==3.5.0.3
celery==4.1.0
Django==1.8.5
eventlet==0.21.0
kombu==4.1.0
pytz==2017.2
vine==1.1.4
chrisspen commentedon Aug 10, 2017
I'm having this same problem with RabbitMQ running on localhost. It's odd that local connections would time-out or lose connection. I do have some pretty intensive tasks, and my CPU is at 100%, but my memory usage is low. Would that cause dropped connections?
Shuklapreetika commentedon Oct 12, 2017
@chrisspen, were you able to resolve the issue? I am having a similar scenario, where while performing an CPU intensive task, the connection to redis gets dropped: the following is one of the many manifestation of exceptions which I receive:
imaia commentedon Oct 31, 2017
I also had a " Connection to broker lost" using rabbit + celery under high CPU usage; not sure is related.
auvipy commentedon Jan 17, 2018
this might be an issue with HAProxy
42 remaining items
atodniAr commentedon Jun 9, 2021
I had an application using celery with redis backend (haproxy) over k8s.
Facts:
Thus, I think celery consumer lack a proper heartbeat with haproxy, which caused haproxy to break the connection on idle.
thedrow commentedon Aug 17, 2021
Didn't this help?
We just need to document this if that works.
laczar commentedon Nov 29, 2021
is this solution applied or being planned on celery?
hamid914 commentedon Dec 23, 2021
I had this error with
amqp==5.0.8and it is fixed by upgrading toamqp==5.0.9cathhuo commentedon Oct 14, 2022
i have the same issue in 5.2.7
vlad-stack commentedon Nov 26, 2022
I have the same issue in 5.2.7, and 5.3.0b1
DAAworld commentedon Oct 25, 2023
kombu==5.3.2
celery==5.3.4
redis==5.0.0
my config
BROKER_CONNECTION_MAX_RETRIES = 0
CELERY_REDIS_RETRY_ON_TIMEOUT = True
CELERY_REDIS_SOCKET_CONNECT_TIMEOUT = 5
REDIS_BACKEND_HEALTH_CHECK_INTERVAL = 5
I closed my internet about 1 minutes, and celery beat was retried successed, but worker raise error :
[2023-10-25 17:22:12,954: WARNING/MainProcess] consumer: Connection to broker lost. Trying to re-establish the connection...
Traceback (most recent call last):
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/redis/connection.py", line 435, in send_packed_command
self._sock.sendall(item)
ConnectionResetError: [Errno 104] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/celery/worker/consumer/consumer.py", line 340, in start
blueprint.start(self)
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/celery/bootsteps.py", line 116, in start
step.start(parent)
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/celery/worker/consumer/consumer.py", line 742, in start
c.loop(*c.loop_args())
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/celery/worker/loops.py", line 97, in asynloop
next(loop)
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/kombu/asynchronous/hub.py", line 373, in create_loop
cb(*cbargs)
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/kombu/transport/redis.py", line 1341, in on_readable
self.cycle.on_readable(fileno)
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/kombu/transport/redis.py", line 566, in on_readable
chan.handlerstype
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/kombu/transport/redis.py", line 910, in _receive
ret.append(self._receive_one(c))
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/kombu/transport/redis.py", line 920, in _receive_one
response = c.parse_response()
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/redis/client.py", line 786, in parse_response
self.check_health()
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/redis/client.py", line 824, in check_health
conn.send_command("PING", self.HEALTH_CHECK_MESSAGE, check_health=False)
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/redis/connection.py", line 457, in send_command
self.send_packed_command(
File "/home/ww/miniconda3/envs/sss/lib/python3.10/site-packages/redis/connection.py", line 446, in send_packed_command
raise ConnectionError(f"Error {errno} while writing to socket. {errmsg}.")
redis.exceptions.ConnectionError: Error 104 while writing to socket. Connection reset by peer.
Downgrading celery to 3.1.25