首页 > 解决方案 > Celery worker - ConnectionResetError: [WinError 10054] 现有连接被远程主机强行关闭

问题描述

执行长时间运行的任务时,Celery 连接中断。我使用 amqp 作为代理,使用 redis 作为后端。

Celery 在远程主机上运行,​​我用于 celery worker 的命令如下

pipenv run celery worker -A src.celery_app -l info -P gevent --without-mingle --without-heartbeat --without-gossip -Q queue1 -n worker1

错误日志如下:-

[2020-09-09 14:26:46,820: CRITICAL/MainProcess] Couldn't ack 1, reason:ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)
Traceback (most recent call last):
  File "c:\users\g-us01.test\.virtualenvs\celery-z5n-38vt\lib\site-packages\kombu\message.py", line 131, in ack_log_error
    self.ack(multiple=multiple)
  File "c:\users\g-us01.test\.virtualenvs\celery-z5n-38vt\lib\site-packages\kombu\message.py", line 126, in ack
    self.channel.basic_ack(self.delivery_tag, multiple=multiple)
  File "c:\users\g-us01.test\.virtualenvs\celery-z5n-38vt\lib\site-packages\amqp\channel.py", line 1394, in basic_ack
    spec.Basic.Ack, argsig, (delivery_tag, multiple),
  File "c:\users\g-us01.test\.virtualenvs\celery-z5n-38vt\lib\site-packages\amqp\abstract_channel.py", line 59, in send_method
    conn.frame_writer(1, self.channel_id, sig, args, content)
  File "c:\users\g-us01.test\.virtualenvs\celery-z5n-38vt\lib\site-packages\amqp\method_framing.py", line 189, in write_frame
    write(view[:offset])
  File "c:\users\g-us01.test\.virtualenvs\celery-z5n-38vt\lib\site-packages\amqp\transport.py", line 305, in write
    self._write(s)
  File "c:\users\g-us01.test\.virtualenvs\celery-z5n-38vt\lib\site-packages\gevent\_socket3.py", line 534, in sendall
    return _socketcommon._sendall(self, data_memory, flags)
  File "c:\users\g-us01.test\.virtualenvs\celery-z5n-38vt\lib\site-packages\gevent\_socketcommon.py", line 392, in _sendall
    timeleft = __send_chunk(socket, chunk, flags, timeleft, end)
  File "c:\users\g-us01.test\.virtualenvs\celery-z5n-38vt\lib\site-packages\gevent\_socketcommon.py", line 321, in __send_chunk
    data_sent += socket.send(chunk, flags)
  File "c:\users\g-us01.test\.virtualenvs\celery-z5n-38vt\lib\site-packages\gevent\_socket3.py", line 515, in send
    return self._sock.send(data, flags)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

无法理解为什么会发生此错误。

标签: pythoncelery

解决方案


推荐阅读