Skip to content

Commit

Permalink
fix: Prevent redis task loss when closing connection while in poll (#…
Browse files Browse the repository at this point in the history
…1733)

* Catch brpop before closing connection

* Update unit test

---------

Co-authored-by: mbierma <[email protected]>
  • Loading branch information
mbierma and mbierma authored Aug 15, 2023
1 parent 6f86766 commit 492776e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kombu/transport/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,11 @@ def _purge(self, queue):

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)
Expand Down
9 changes: 9 additions & 0 deletions t/unit/transport/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,15 @@ def test_close_disconnects(self):
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):
Expand Down

0 comments on commit 492776e

Please sign in to comment.