Skip to content

Commit

Permalink
Merge pull request #198 from pahaz/pahaz-patch-shutdown
Browse files Browse the repository at this point in the history
sshtunnel: picked from #184 (close #170)
  • Loading branch information
pahaz authored Oct 24, 2020
2 parents b7905f9 + 0e9d969 commit 8cb68a6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sshtunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,9 @@ def __init__(self, *args, **kwargs):

def handle_error(self, request, client_address):
(exc_class, exc, tb) = sys.exc_info()
self.logger.error('Could not establish connection from {0} to remote '
'side of the tunnel'.format(request.getsockname()))
self.logger.error('Could not establish connection from local {0} '
'to remote {1} side of the tunnel'
.format(request.getsockname(), self.remote_address))
self.tunnel_ok.put(False)

@property
Expand Down Expand Up @@ -1404,10 +1405,13 @@ def _stop_transport(self):
HandlerSSHTunnelForwarderError) as e:
self.logger.warning(e)
for _srv in self._server_list:
tunnel = _srv.local_address
if self.tunnel_is_up[tunnel]:
self.logger.info('Shutting down tunnel {0}'.format(tunnel))
_srv.shutdown()
status = 'up' if self.tunnel_is_up[_srv.local_address] else 'down'
self.logger.info('Shutting down tunnel: {0} <> {1} ({2})'.format(
address_to_str(_srv.local_address),
address_to_str(_srv.remote_address),
status
))
_srv.shutdown()
_srv.server_close()
# clean up the UNIX domain socket if we're using one
if isinstance(_srv, _UnixStreamForwardServer):
Expand Down

0 comments on commit 8cb68a6

Please sign in to comment.