Navigation Menu

Skip to content

Commit

Permalink
increase default ssh tunnel timeout to 60 seconds
Browse files Browse the repository at this point in the history
also expose timeout to tunnel_connection function
  • Loading branch information
minrk committed Aug 17, 2011
1 parent 34eefb9 commit 65d9f3e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions IPython/external/ssh/tunnel.py
Expand Up @@ -122,7 +122,7 @@ def _try_passwordless_paramiko(server, keyfile):
return True


def tunnel_connection(socket, addr, server, keyfile=None, password=None, paramiko=None):
def tunnel_connection(socket, addr, server, keyfile=None, password=None, paramiko=None, timeout=60):
"""Connect a socket to an address via an ssh tunnel.
This is a wrapper for socket.connect(addr), when addr is not accessible
Expand All @@ -131,12 +131,12 @@ def tunnel_connection(socket, addr, server, keyfile=None, password=None, paramik
selected local port of the tunnel.
"""
new_url, tunnel = open_tunnel(addr, server, keyfile=keyfile, password=password, paramiko=paramiko)
new_url, tunnel = open_tunnel(addr, server, keyfile=keyfile, password=password, paramiko=paramiko, timeout=timeout)
socket.connect(new_url)
return tunnel


def open_tunnel(addr, server, keyfile=None, password=None, paramiko=None):
def open_tunnel(addr, server, keyfile=None, password=None, paramiko=None, timeout=60):
"""Open a tunneled connection from a 0MQ url.
For use inside tunnel_connection.
Expand All @@ -157,10 +157,11 @@ def open_tunnel(addr, server, keyfile=None, password=None, paramiko=None):
tunnelf = paramiko_tunnel
else:
tunnelf = openssh_tunnel
tunnel = tunnelf(lport, rport, server, remoteip=ip, keyfile=keyfile, password=password)

tunnel = tunnelf(lport, rport, server, remoteip=ip, keyfile=keyfile, password=password, timeout=timeout)
return 'tcp://127.0.0.1:%i'%lport, tunnel

def openssh_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, password=None, timeout=15):
def openssh_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, password=None, timeout=60):
"""Create an ssh tunnel using command-line ssh that connects port lport
on this machine to localhost:rport on server. The tunnel
will automatically close when not in use, remaining open
Expand Down Expand Up @@ -192,7 +193,9 @@ def openssh_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, pas
password : str;
Your ssh password to the ssh server. Note that if this is left None,
you will be prompted for it if passwordless key based login is unavailable.
timeout : int [default: 60]
The time (in seconds) after which no activity will result in the tunnel
closing. This prevents orphaned tunnels from running forever.
"""
if pexpect is None:
raise ImportError("pexpect unavailable, use paramiko_tunnel")
Expand Down Expand Up @@ -236,7 +239,7 @@ def _split_server(server):
port = 22
return username, server, port

def paramiko_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, password=None, timeout=15):
def paramiko_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, password=None, timeout=60):
"""launch a tunner with paramiko in a subprocess. This should only be used
when shell ssh is unavailable (e.g. Windows).
Expand Down Expand Up @@ -271,6 +274,9 @@ def paramiko_tunnel(lport, rport, server, remoteip='127.0.0.1', keyfile=None, pa
password : str;
Your ssh password to the ssh server. Note that if this is left None,
you will be prompted for it if passwordless key based login is unavailable.
timeout : int [default: 60]
The time (in seconds) after which no activity will result in the tunnel
closing. This prevents orphaned tunnels from running forever.
"""
if paramiko is None:
Expand Down

0 comments on commit 65d9f3e

Please sign in to comment.