diff --git a/kombu/transport/redis.py b/kombu/transport/redis.py index f1d5034e..2d932e97 100644 --- a/kombu/transport/redis.py +++ b/kombu/transport/redis.py @@ -1079,6 +1079,11 @@ class Channel(virtual.Channel): def close(self): self._closing = True + if self._in_poll: + try: + self._brpop_read() + except Empty: + pass if not self.closed: # remove from channel poller. self.connection.cycle.discard(self) diff --git a/t/unit/transport/test_redis.py b/t/unit/transport/test_redis.py index b14408a6..a5fa5ea0 100644 --- a/t/unit/transport/test_redis.py +++ b/t/unit/transport/test_redis.py @@ -1290,6 +1290,15 @@ class test_Redis: assert conn1.disconnected assert conn2.disconnected + def test_close_in_poll(self): + c = Connection(transport=Transport).channel() + conn1 = c.client.connection + conn1._sock.data = [('BRPOP', ('test_Redis',))] + c._in_poll = True + c.close() + assert conn1.disconnected + assert conn1._sock.data == [] + def test_get__Empty(self): channel = self.connection.channel() with pytest.raises(Empty):