You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we try to establish SSH tunnel with connectivity checking to some service that is unavailable we will get thread leaking.
Here is the thing:
When sshtunnel.start() function is called it creates new thread that uses socketserver package serve_forever function as infinite loop that can be broken by setting special flag - __shutdown_request. This flag is set by sshtunnel module when we call it stop() function. The stop function sets __shutdown_request flag in the case when the tunnel_is_up flag are set. If we check remote service availability and it's not available the tunnel_is_up flag is in False state and early created thread is not closed by stop method. The problem can be easily fixed this way:
def_stop_transport(self):
""" Close the underlying transport when nothing more is needed """try:
self._check_is_started()
except (BaseSSHTunnelForwarderError,
HandlerSSHTunnelForwarderError) ase:
self.logger.warning(e)
for_srvinself._server_list:
tunnel=_srv.local_addressifself.tunnel_is_up[tunnel]:
self.logger.info('Shutting down tunnel {0}'.format(tunnel))
_srv.shutdown()
_srv.server_close()
# clean up the UNIX domain socket if we're using oneifisinstance(_srv, _UnixStreamForwardServer):
try:
os.unlink(_srv.local_address)
exceptExceptionase:
self.logger.error('Unable to unlink socket {0}: {1}'
.format(self.local_address, repr(e)))
The problem can be easily reproduced by a code in the file:
If we try to establish SSH tunnel with connectivity checking to some service that is unavailable we will get thread leaking.
Here is the thing:
When sshtunnel.start() function is called it creates new thread that uses socketserver package serve_forever function as infinite loop that can be broken by setting special flag - __shutdown_request. This flag is set by sshtunnel module when we call it stop() function. The stop function sets __shutdown_request flag in the case when the tunnel_is_up flag are set. If we check remote service availability and it's not available the tunnel_is_up flag is in False state and early created thread is not closed by stop method. The problem can be easily fixed this way:
The problem can be easily reproduced by a code in the file:
thread_leaks_example.txt
The text was updated successfully, but these errors were encountered: