Skip to content

Commit

Permalink
patch from andreux fort: add a timeout to the key exchange, so that i…
Browse files Browse the repository at this point in the history
…f the remote side doesn't ever answer, eventually we give up. bug #378511
  • Loading branch information
Robey Pointer committed Jul 19, 2009
1 parent fe35f44 commit 15f4bdb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions paramiko/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def __init__(self, sock):
self.saved_exception = None
self.clear_to_send = threading.Event()
self.clear_to_send_lock = threading.Lock()
self.clear_to_send_timeout = 30.0
self.log_name = 'paramiko.transport'
self.logger = util.get_logger(self.log_name)
self.packetizer.set_log(self.logger)
Expand Down Expand Up @@ -1402,6 +1403,7 @@ def _send_user_message(self, data):
send a message, but block if we're in key negotiation. this is used
for user-initiated requests.
"""
start = time.time()
while True:
self.clear_to_send.wait(0.1)
if not self.active:
Expand All @@ -1411,6 +1413,8 @@ def _send_user_message(self, data):
if self.clear_to_send.isSet():
break
self.clear_to_send_lock.release()
if time.time() > start + self.clear_to_send_timeout:
raise SSHException('Key-exchange timed out waiting for key negotiation')
try:
self._send_message(data)
finally:
Expand Down

0 comments on commit 15f4bdb

Please sign in to comment.