mirror of https://github.com/celery/kombu.git
prevent event loop polling on closed redis transports (and causing leak)
This commit is contained in:
parent
507b306400
commit
47781af050
|
@ -1237,6 +1237,12 @@ class Transport(virtual.Transport):
|
|||
def _on_disconnect(connection):
|
||||
if connection._sock:
|
||||
loop.remove(connection._sock)
|
||||
|
||||
# stop polling in the event loop
|
||||
try:
|
||||
loop.on_tick.remove(on_poll_start)
|
||||
except KeyError:
|
||||
pass
|
||||
cycle._on_connection_disconnect = _on_disconnect
|
||||
|
||||
def on_poll_start():
|
||||
|
|
|
@ -854,6 +854,21 @@ class test_Channel:
|
|||
call(13, transport.on_readable, 13),
|
||||
])
|
||||
|
||||
def test_register_with_event_loop__on_disconnect__loop_cleanup(self):
|
||||
"""Ensure event loop polling stops on disconnect."""
|
||||
transport = self.connection.transport
|
||||
self.connection._sock = None
|
||||
transport.cycle = Mock(name='cycle')
|
||||
transport.cycle.fds = {12: 'LISTEN', 13: 'BRPOP'}
|
||||
conn = Mock(name='conn')
|
||||
conn.client = Mock(name='client', transport_options={})
|
||||
loop = Mock(name='loop')
|
||||
loop.on_tick = set()
|
||||
redis.Transport.register_with_event_loop(transport, conn, loop)
|
||||
assert len(loop.on_tick) == 1
|
||||
transport.cycle._on_connection_disconnect(self.connection)
|
||||
assert loop.on_tick == set()
|
||||
|
||||
def test_configurable_health_check(self):
|
||||
transport = self.connection.transport
|
||||
transport.cycle = Mock(name='cycle')
|
||||
|
|
Loading…
Reference in New Issue