套接字已关闭,客户端Celery worker使用RabbitMQ丢失了心跳

问题描述 投票:2回答:1

我创建了Flask应用程序服务器,该服务器允许在一个端点上生成Celery worker。然后,您可以将任务应用于连接到worker的特定队列。

一切正常,直到不超过2分钟不使用工人为止。然后RabbitMQ记录消息

rabbit_1         | 2018-12-29 15:51:21.573 [error] <0.30372.0> closing AMQP connection <0.30372.0> (172.18.0.1:50058 -> 172.18.0.4:5672):
rabbit_1         | missed heartbeats from client, timeout: 60s

来自应用程序的堆栈跟踪

> [2018-12-29 16:51:26,526] ERROR in app: Exception on /sentiment [POST]
> Traceback (most recent call last):   File
> "/home/konrad/anaconda3/lib/python3.6/site-packages/flask/app.py",
> line 1612, in full_dispatch_request
>     rv = self.dispatch_request()   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask/app.py",
> line 1598, in dispatch_request
>     return self.view_functions[rule.endpoint](**req.view_args)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask_restplus/api.py",
> line 325, in wrapper
>     resp = resource(*args, **kwargs)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask/views.py",
> line 84, in view
>     return self.dispatch_request(*args, **kwargs)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask_restplus/resource.py",
> line 44, in dispatch_request
>     resp = meth(*args, **kwargs)   File "/home/konrad/Documents/ubuntu-docs/python-dev/crypto-ticker-sentiment/sentinet/evaluation_server/routes/sentiment.py",
> line 25, in post
>     prediction = predict_sentiment(queue, text)   File "/home/konrad/Documents/ubuntu-docs/python-dev/crypto-ticker-sentiment/sentinet/evaluation_server/services/evaluation.py",
> line 17, in predict_sentiment
>     task_result = task.get()   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/result.py",
> line 224, in get
>     on_message=on_message,   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
> line 188, in wait_for_pending
>     for _ in self._wait_for_pending(result, **kwargs):   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
> line 255, in _wait_for_pending
>     on_interval=on_interval):   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
> line 56, in drain_events_until
>     yield self.wait_for(p, wait, timeout=1)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
> line 65, in wait_for
>     wait(timeout=timeout)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/rpc.py",
> line 63, in drain_events
>     return self._connection.drain_events(timeout=timeout)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/kombu/connection.py",
> line 301, in drain_events
>     return self.transport.drain_events(self.connection, **kwargs)   File
> "/home/konrad/anaconda3/lib/python3.6/site-packages/kombu/transport/pyamqp.py",
> line 103, in drain_events
>     return connection.drain_events(**kwargs)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/connection.py",
> line 491, in drain_events
>     while not self.blocking_read(timeout):   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/connection.py",
> line 496, in blocking_read
>     frame = self.transport.read_frame()   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/transport.py",
> line 243, in read_frame
>     frame_header = read(7, True)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/transport.py",
> line 426, in _read
>     raise IOError('Socket closed') OSError: Socket closed

我认为这可能是Celery工作者的心跳或RabbitMQ问题。我在工作程序生成时添加了-without-heartbeat选项,但是它没有用。在RabbitMQ上禁用心跳会有所帮助吗?

更新

我在RabbitMQ doc页面上找到了它,但没有说明如何实现。

如何禁用心跳,可以通过设置 客户端和服务器端的超时间隔均为0。

或者,可以使用非常高的值(例如1800秒) 两端可以有效禁用心跳,因为帧传输将 太少见而无法实用。

除非采用TCP Keepalive,否则均不推荐任何做法 具有足够低的不活动检测时间]

更新2

我在[[rabbitmq.conf文件中添加了heartbeat = 0,但仍然无法使用。

python rabbitmq celery
1个回答
0
投票
有关此问题的最新消息吗?我在这里遇到同样的问题。从兔子我可以看到:

missed heartbeats from client, timeout: 120s

并且我已经为worker配置了心跳0,并且我尝试了没有心跳的情况。 

从兔子端,我已经配置了一个大于120秒的值,但是此配置显然被忽略了

root@39f00a8aa08b:/# rabbitmqctl list_connections name timeout Listing connections ... name timeout 10.0.0.2:54758 -> 10.0.0.8:5672 120 10.0.0.2:45014 -> 10.0.0.8:5672 120 10.0.0.2:47454 -> 10.0.0.8:5672 0 10.0.0.2:56630 -> 10.0.0.8:5672 120 10.0.0.2:56637 -> 10.0.0.8:5672 120 10.0.0.2:56640 -> 10.0.0.8:5672 120 root@39f00a8aa08b:/# rabbitmqctl eval 'application:get_env(rabbit, heartbeat).' {ok,1800}

© www.soinside.com 2019 - 2024. All rights reserved.