Skip to content

Commit a4a497f

Browse files
author
Dan
committed
Added tunnel timeout and exception handling to SSHClient - #76
1 parent 3dc71aa commit a4a497f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pssh/ssh_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __init__(self, host,
127127
self._connect_tunnel()
128128
else:
129129
self._connect(self.client, self.host, self.port)
130-
130+
131131
def _connect_tunnel(self):
132132
"""Connects to SSH server via an intermediate SSH tunnel server.
133133
client (me) -> tunnel (ssh server to proxy through) -> \
@@ -145,14 +145,15 @@ def _connect_tunnel(self):
145145
self.proxy_port, self.host, self.port,)
146146
try:
147147
proxy_channel = self.proxy_client.get_transport().open_channel(
148-
'direct-tcpip', (self.host, self.port,), ('127.0.0.1', 0))
148+
'direct-tcpip', (self.host, self.port,), ('127.0.0.1', 0),
149+
timeout=self.timeout)
149150
sleep(0)
150151
return self._connect(self.client, self.host, self.port, sock=proxy_channel)
151-
except ChannelException as ex:
152+
except (ChannelException, paramiko.SSHException) as ex:
152153
error_type = ex.args[1] if len(ex.args) > 1 else ex.args[0]
153154
raise ConnectionErrorException("Error connecting to host '%s:%s' - %s",
154-
self.host, self.port,
155-
str(error_type))
155+
self.host, self.port,
156+
str(error_type))
156157

157158
def _connect(self, client, host, port, sock=None, retries=1,
158159
user=None, password=None, pkey=None):

0 commit comments

Comments
 (0)