celery with rabbitmq Control command error

使用 celery 处理定时任务和异步任务的时候,出现与 rabbitmq 连接中断的问题。具体异常如下:

[2018-09-27 15:37:59,466: ERROR/MainProcess] Control command error: error(32, 'Broken pipe')
Traceback (most recent call last):
  File "/Users/xxx/.virtualenvs/engine_env/lib/python2.7/site-packages/celery/worker/pidbox.py", line 46, in on_message
    self.node.handle_message(body, message)
  File "/Users/xxx/.virtualenvs/engine_env/lib/python2.7/site-packages/kombu/pidbox.py", line 129, in handle_message
    return self.dispatch(**body)
  File "/Users/xxx/.virtualenvs/engine_env/lib/python2.7/site-packages/kombu/pidbox.py", line 112, in dispatch
    ticket=ticket)
  File "/Users/xxx/.virtualenvs/engine_env/lib/python2.7/site-packages/kombu/pidbox.py", line 135, in reply
    serializer=self.mailbox.serializer)
  File "/Users/xxx/.virtualenvs/engine_env/lib/python2.7/site-packages/kombu/pidbox.py", line 265, in _publish_reply
    **opts
  File "/Users/xx/.virtualenvs/engine_env/lib/python2.7/site-packages/kombu/messaging.py", line 181, in publish
    exchange_name, declare,
  File "/Users/xxx/.virtualenvs/engine_env/lib/python2.7/site-packages/kombu/messaging.py", line 203, in _publish
    mandatory=mandatory, immediate=immediate,
  File "/Users/xxx/.virtualenvs/engine_env/lib/python2.7/site-packages/amqp/channel.py", line 1732, in _basic_publish
    (0, exchange, routing_key, mandatory, immediate), msg
  File "/Users/xxx/.virtualenvs/engine_env/lib/python2.7/site-packages/amqp/abstract_channel.py", line 50, in send_method
    conn.frame_writer(1, self.channel_id, sig, args, content)
  File "/Users/xxx/.virtualenvs/engine_env/lib/python2.7/site-packages/amqp/method_framing.py", line 166, in write_frame
    write(view[:offset])
  File "/Users/xxx/.virtualenvs/engine_env/lib/python2.7/site-packages/amqp/transport.py", line 275, in write
    self._write(s)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 32] Broken pipe

查看对应的 rabbitmq 的日志时,如下:

2018-09-27 08:33:00.118 [warning] <0.24461.0> closing AMQP connection <0.24461.0> (172.17.0.1:48858 -> 172.17.0.4:5672):
missed heartbeats from client, timeout: 60s

celeryissue 中找到一些类似的描述,应该是 celery 内部的一个 bug.

但是没有具体的处理方案。

sf 上有个基本的处理方案:

celery 的配置中加上 如下配置:

broker_pool_limit = None

问题: connection-reset-by-peer

推荐阅读更多精彩内容