<h2 dir="auto">Checklist</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="software -&gt; celery:4.2.0rc4 (windowlicker) kombu:4.2.0 py:2.7.12
            billiard:3.5.0.3 py-amqp:2.3.1
platform -&gt; system:Linux arch:64bit, ELF imp:CPython
loader   -&gt; celery.loaders.default.Loader
settings -&gt; transport:amqp results:disabled"><pre class="notranslate"><code class="notranslate">software -&gt; celery:4.2.0rc4 (windowlicker) kombu:4.2.0 py:2.7.12
            billiard:3.5.0.3 py-amqp:2.3.1
platform -&gt; system:Linux arch:64bit, ELF imp:CPython
loader   -&gt; celery.loaders.default.Loader
settings -&gt; transport:amqp results:disabled
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
</ul>
<p dir="auto">Celery versions affected: 4.2.0rc4, 4.2.0rc2<br>
Last working version: 4.1.1</p>
<h2 dir="auto">Steps to reproduce</h2>
<ol dir="auto">
<li>Start up a worker with gevent pool</li>
<li>send celery control cancel_consumer remote comand</li>
<li>Send celery control add_consumer remote command</li>
</ol>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">Cancel consumer should remove all the workers consuming from the given queue<br>
Add consumer should add a specified consumer to the given queue</p>
<h2 dir="auto">Actual behavior</h2>
<p dir="auto">Cancel consumer removes the workers from the queue as expected<br>
Add consumer throws the following exception and the worker dies</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
worker_1                                    |   File &quot;/usr/local/lib/python2.7/site-packages/gevent/hub.py&quot;, line 866, in switch
worker_1                                    |     switch(value)
worker_1                                    |   File &quot;/usr/local/lib/python2.7/site-packages/celery/worker/pidbox.py&quot;, line 120, in loop
worker_1                                    |     connection.drain_events(timeout=1.0)
worker_1                                    |   File &quot;/usr/local/lib/python2.7/site-packages/kombu/connection.py&quot;, line 301, in drain_events
worker_1                                    |     return self.transport.drain_events(self.connection, **kwargs)
worker_1                                    |   File &quot;/usr/local/lib/python2.7/site-packages/kombu/transport/pyamqp.py&quot;, line 103, in drain_events
worker_1                                    |     return connection.drain_events(**kwargs)
worker_1                                    |   File &quot;/usr/local/lib/python2.7/site-packages/amqp/connection.py&quot;, line 491, in drain_events
worker_1                                    |     while not self.blocking_read(timeout):
worker_1                                    |   File &quot;/usr/local/lib/python2.7/site-packages/amqp/connection.py&quot;, line 496, in blocking_read
worker_1                                    |     frame = self.transport.read_frame()
worker_1                                    |   File &quot;/usr/local/lib/python2.7/site-packages/amqp/transport.py&quot;, line 243, in read_frame
worker_1                                    |     frame_header = read(7, True)
worker_1                                    |   File &quot;/usr/local/lib/python2.7/site-packages/amqp/transport.py&quot;, line 418, in _read
worker_1                                    |     s = recv(n - len(rbuf))
worker_1                                    |   File &quot;/usr/local/lib/python2.7/site-packages/gevent/_socket2.py&quot;, line 277, in recv
worker_1                                    |     return sock.recv(*args)
worker_1                                    | error: [Errno 104] Connection reset by peer
worker_1                                    | Mon May 28 19:40:01 2018 &lt;built-in method switch of greenlet.greenlet object at 0x7f5b24653c30&gt; failed with error"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
worker_1                                    |   File "/usr/local/lib/python2.7/site-packages/gevent/hub.py", line 866, in switch
worker_1                                    |     switch(value)
worker_1                                    |   File "/usr/local/lib/python2.7/site-packages/celery/worker/pidbox.py", line 120, in loop
worker_1                                    |     connection.drain_events(timeout=1.0)
worker_1                                    |   File "/usr/local/lib/python2.7/site-packages/kombu/connection.py", line 301, in drain_events
worker_1                                    |     return self.transport.drain_events(self.connection, **kwargs)
worker_1                                    |   File "/usr/local/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 103, in drain_events
worker_1                                    |     return connection.drain_events(**kwargs)
worker_1                                    |   File "/usr/local/lib/python2.7/site-packages/amqp/connection.py", line 491, in drain_events
worker_1                                    |     while not self.blocking_read(timeout):
worker_1                                    |   File "/usr/local/lib/python2.7/site-packages/amqp/connection.py", line 496, in blocking_read
worker_1                                    |     frame = self.transport.read_frame()
worker_1                                    |   File "/usr/local/lib/python2.7/site-packages/amqp/transport.py", line 243, in read_frame
worker_1                                    |     frame_header = read(7, True)
worker_1                                    |   File "/usr/local/lib/python2.7/site-packages/amqp/transport.py", line 418, in _read
worker_1                                    |     s = recv(n - len(rbuf))
worker_1                                    |   File "/usr/local/lib/python2.7/site-packages/gevent/_socket2.py", line 277, in recv
worker_1                                    |     return sock.recv(*args)
worker_1                                    | error: [Errno 104] Connection reset by peer
worker_1                                    | Mon May 28 19:40:01 2018 &lt;built-in method switch of greenlet.greenlet object at 0x7f5b24653c30&gt; failed with error
</code></pre></div>
<p dir="auto">Celery version: <code class="notranslate">4.2.0</code></p>
<h2 dir="auto">Steps to reproduce</h2>
<p dir="auto">docker-compose.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="version: '2'

services:
  worker:
    build: .
    depends_on:
      - rabbitmq

  rabbitmq:
    image: rabbitmq:alpine"><pre class="notranslate"><span class="pl-ent">version</span>: <span class="pl-s"><span class="pl-pds">'</span>2<span class="pl-pds">'</span></span>

<span class="pl-ent">services</span>:
  <span class="pl-ent">worker</span>:
    <span class="pl-ent">build</span>: <span class="pl-s">.</span>
    <span class="pl-ent">depends_on</span>:
      - <span class="pl-s">rabbitmq</span>

  <span class="pl-ent">rabbitmq</span>:
    <span class="pl-ent">image</span>: <span class="pl-s">rabbitmq:alpine</span></pre></div>
<p dir="auto">Dockerfile</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="FROM alpine

RUN apk add --no-cache build-base python3 python3-dev
RUN pip3 install celery eventlet

CMD celery -b amqp://rabbitmq worker -P eventlet --loglevel=DEBUG"><pre class="notranslate"><code class="notranslate">FROM alpine

RUN apk add --no-cache build-base python3 python3-dev
RUN pip3 install celery eventlet

CMD celery -b amqp://rabbitmq worker -P eventlet --loglevel=DEBUG
</code></pre></div>
<div class="highlight highlight-text-shell-session notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ docker-compose up --build"><pre class="notranslate">$ <span class="pl-s1">docker-compose up --build</span></pre></div>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">Worker stays connected without errors</p>
<h2 dir="auto">Actual behavior</h2>
<p dir="auto">3 minutes after startup, the worker reports several errors with a Traceback, similar to the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[2018-06-14 20:11:44,213: WARNING/MainProcess] Traceback (most recent call last):
[2018-06-14 20:11:44,213: WARNING/MainProcess] File &quot;/usr/lib/python3.6/site-packages/eventlet/hubs/poll.py&quot;, line 114, in wait
    listener.cb(fileno)
[2018-06-14 20:11:44,214: WARNING/MainProcess] File &quot;/usr/lib/python3.6/site-packages/celery/worker/pidbox.py&quot;, line 120, in loop
    connection.drain_events(timeout=1.0)
[2018-06-14 20:11:44,214: WARNING/MainProcess] File &quot;/usr/lib/python3.6/site-packages/kombu/connection.py&quot;, line 301, in drain_events
    return self.transport.drain_events(self.connection, **kwargs)
[2018-06-14 20:11:44,215: WARNING/MainProcess] File &quot;/usr/lib/python3.6/site-packages/kombu/transport/pyamqp.py&quot;, line 103, in drain_events
    return connection.drain_events(**kwargs)
[2018-06-14 20:11:44,216: WARNING/MainProcess] File &quot;/usr/lib/python3.6/site-packages/amqp/connection.py&quot;, line 491, in drain_events
    while not self.blocking_read(timeout):
[2018-06-14 20:11:44,217: WARNING/MainProcess] File &quot;/usr/lib/python3.6/site-packages/amqp/connection.py&quot;, line 496, in blocking_read
    frame = self.transport.read_frame()
[2018-06-14 20:11:44,217: WARNING/MainProcess] File &quot;/usr/lib/python3.6/site-packages/amqp/transport.py&quot;, line 243, in read_frame
    frame_header = read(7, True)
[2018-06-14 20:11:44,218: WARNING/MainProcess] File &quot;/usr/lib/python3.6/site-packages/amqp/transport.py&quot;, line 426, in _read
    raise IOError('Socket closed')
[2018-06-14 20:11:44,218: WARNING/MainProcess] OSError: Socket closed
[2018-06-14 20:11:44,219: WARNING/MainProcess] Removing descriptor: 7"><pre class="notranslate"><code class="notranslate">[2018-06-14 20:11:44,213: WARNING/MainProcess] Traceback (most recent call last):
[2018-06-14 20:11:44,213: WARNING/MainProcess] File "/usr/lib/python3.6/site-packages/eventlet/hubs/poll.py", line 114, in wait
    listener.cb(fileno)
[2018-06-14 20:11:44,214: WARNING/MainProcess] File "/usr/lib/python3.6/site-packages/celery/worker/pidbox.py", line 120, in loop
    connection.drain_events(timeout=1.0)
[2018-06-14 20:11:44,214: WARNING/MainProcess] File "/usr/lib/python3.6/site-packages/kombu/connection.py", line 301, in drain_events
    return self.transport.drain_events(self.connection, **kwargs)
[2018-06-14 20:11:44,215: WARNING/MainProcess] File "/usr/lib/python3.6/site-packages/kombu/transport/pyamqp.py", line 103, in drain_events
    return connection.drain_events(**kwargs)
[2018-06-14 20:11:44,216: WARNING/MainProcess] File "/usr/lib/python3.6/site-packages/amqp/connection.py", line 491, in drain_events
    while not self.blocking_read(timeout):
[2018-06-14 20:11:44,217: WARNING/MainProcess] File "/usr/lib/python3.6/site-packages/amqp/connection.py", line 496, in blocking_read
    frame = self.transport.read_frame()
[2018-06-14 20:11:44,217: WARNING/MainProcess] File "/usr/lib/python3.6/site-packages/amqp/transport.py", line 243, in read_frame
    frame_header = read(7, True)
[2018-06-14 20:11:44,218: WARNING/MainProcess] File "/usr/lib/python3.6/site-packages/amqp/transport.py", line 426, in _read
    raise IOError('Socket closed')
[2018-06-14 20:11:44,218: WARNING/MainProcess] OSError: Socket closed
[2018-06-14 20:11:44,219: WARNING/MainProcess] Removing descriptor: 7
</code></pre></div>
<p dir="auto">In addition, the rabbitmq server reports warnings similar to the following (repeated twice):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2018-06-14 20:11:44.209 [warning] &lt;0.586.0&gt; closing AMQP connection &lt;0.586.0&gt; (172.19.0.3:42678 -&gt; 172.19.0.2:5672):
missed heartbeats from client, timeout: 60s"><pre class="notranslate"><code class="notranslate">2018-06-14 20:11:44.209 [warning] &lt;0.586.0&gt; closing AMQP connection &lt;0.586.0&gt; (172.19.0.3:42678 -&gt; 172.19.0.2:5672):
missed heartbeats from client, timeout: 60s
</code></pre></div>