Fix leak of SaltMessageClient instances when using tcp transport

This commit is contained in:
Andrei Zene 2019-03-20 16:52:03 +02:00 committed by Daniel A. Wozniak
parent fd6cb35093
commit 9a4b407761
No known key found for this signature in database
GPG key ID: 166B9D2C06C82D61

View file

@ -933,6 +933,10 @@ class SaltMessageClient(object):
self._stream_return_future = tornado.concurrent.Future()
self.io_loop.spawn_callback(self._stream_return)
def _stop_io_loop(self):
if self.io_loop is not None:
self.io_loop.stop()
# TODO: timeout inflight sessions
def close(self):
if self._closing:
@ -957,15 +961,20 @@ class SaltMessageClient(object):
# 'StreamClosedError' when the stream is closed.
if self._read_until_future.done():
self._read_until_future.exception()
elif self.io_loop != tornado.ioloop.IOLoop.current(instance=False):
if (self.io_loop != tornado.ioloop.IOLoop.current(instance=False)
or not self._stream_return_future.done()):
self.io_loop.add_future(
self._stream_return_future,
lambda future: self.io_loop.stop()
lambda future: self._stop_io_loop()
)
self.io_loop.start()
except Exception as e:
log.info('Exception caught in SaltMessageClient.close: %s', str(e))
finally:
orig_loop.make_current()
self._tcp_client.close()
self.io_loop = None
self._read_until_future = None
# Clear callback references to allow the object that they belong to
# to be deleted.
self.connect_callback = None