title: Socket closed, missed heartbeats from client Celery worker with RabbitMQ
body: <p>I create Flask application server which allows on one endpoint to spawn Celery worker. On second you can apply task to a specific queue connected to worker.</p>
  
  <p>Everything works fine until worker is not used for more than 2 minutes.
  Then RabbitMQ logs message</p>
  
  <pre><code>rabbit_1         | 2018-12-29 15:51:21.573 [error] &lt;0.30372.0&gt; closing AMQP connection &lt;0.30372.0&gt; (172.18.0.1:50058 -&gt; 172.18.0.4:5672):
  rabbit_1         | missed heartbeats from client, timeout: 60s
  </code></pre>
  
  <p>Stack trace from app</p>
  
  <pre><code>&gt; [2018-12-29 16:51:26,526] ERROR in app: Exception on /sentiment [POST]
  &gt; Traceback (most recent call last):   File
  &gt; "/home/konrad/anaconda3/lib/python3.6/site-packages/flask/app.py",
  &gt; line 1612, in full_dispatch_request
  &gt;     rv = self.dispatch_request()   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask/app.py",
  &gt; line 1598, in dispatch_request
  &gt;     return self.view_functions[rule.endpoint](**req.view_args)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask_restplus/api.py",
  &gt; line 325, in wrapper
  &gt;     resp = resource(*args, **kwargs)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask/views.py",
  &gt; line 84, in view
  &gt;     return self.dispatch_request(*args, **kwargs)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask_restplus/resource.py",
  &gt; line 44, in dispatch_request
  &gt;     resp = meth(*args, **kwargs)   File "/home/konrad/Documents/ubuntu-docs/python-dev/crypto-ticker-sentiment/sentinet/evaluation_server/routes/sentiment.py",
  &gt; line 25, in post
  &gt;     prediction = predict_sentiment(queue, text)   File "/home/konrad/Documents/ubuntu-docs/python-dev/crypto-ticker-sentiment/sentinet/evaluation_server/services/evaluation.py",
  &gt; line 17, in predict_sentiment
  &gt;     task_result = task.get()   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/result.py",
  &gt; line 224, in get
  &gt;     on_message=on_message,   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
  &gt; line 188, in wait_for_pending
  &gt;     for _ in self._wait_for_pending(result, **kwargs):   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
  &gt; line 255, in _wait_for_pending
  &gt;     on_interval=on_interval):   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
  &gt; line 56, in drain_events_until
  &gt;     yield self.wait_for(p, wait, timeout=1)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
  &gt; line 65, in wait_for
  &gt;     wait(timeout=timeout)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/rpc.py",
  &gt; line 63, in drain_events
  &gt;     return self._connection.drain_events(timeout=timeout)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/kombu/connection.py",
  &gt; line 301, in drain_events
  &gt;     return self.transport.drain_events(self.connection, **kwargs)   File
  &gt; "/home/konrad/anaconda3/lib/python3.6/site-packages/kombu/transport/pyamqp.py",
  &gt; line 103, in drain_events
  &gt;     return connection.drain_events(**kwargs)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/connection.py",
  &gt; line 491, in drain_events
  &gt;     while not self.blocking_read(timeout):   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/connection.py",
  &gt; line 496, in blocking_read
  &gt;     frame = self.transport.read_frame()   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/transport.py",
  &gt; line 243, in read_frame
  &gt;     frame_header = read(7, True)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/transport.py",
  &gt; line 426, in _read
  &gt;     raise IOError('Socket closed') OSError: Socket closed
  </code></pre>
  
  <p>I think that may be something with heartbeats from Celery worker or the RabbitMQ issue.
  I added <strong>--without-heartbeat</strong> option on worker spawning but it didn't work.
  Will disabling heartbeats on RabbitMQ help?  </p>
  
  <h2>Update</h2>
  
  <p>I found it on the RabbitMQ <a href="https://www.rabbitmq.com/heartbeats.html" rel="nofollow noreferrer">doc</a> page but it doesn't say how to achieve it.</p>
  
  <blockquote>
    <p>How to Disable Heartbeats Heartbeats can be disabled by setting the
    timeout interval to 0 on both client and server ends.</p>
    
    <p>Alternatively a very high (say, 1800 seconds) value can be used on
    both ends to effectively disable heartbeats as frame delivery will be
    too infrequent to make a practical difference.</p>
    
    <p>Neither practice is recommended unless TCP keepalives are used instead
    with an adequately low inactivity detection period</p>
  </blockquote>
  
  <h2>Update 2</h2>
  
  <p>I added <code>heartbeat = 0</code> to <strong>rabbitmq.conf</strong> file and it still doesn't work.</p>