Skip to content

Commit

Permalink
Custom socket connect timeout in Session()
Browse files Browse the repository at this point in the history
  • Loading branch information
akhil-jha authored and JacobCallahan committed May 11, 2023
1 parent 74e9d6b commit e34979b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions broker/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def connect(
password=password,
port=_port,
key_filename=key_filename,
timeout=timeout
)

def close(self):
Expand Down
3 changes: 2 additions & 1 deletion broker/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def __init__(self, **kwargs):
sock.settimeout(kwargs.get("timeout"))
port = kwargs.get("port", 22)
key_filename = kwargs.get("key_filename")
helpers.simple_retry(sock.connect, [(host, port)])
timeout = kwargs.get("timeout", 60)
helpers.simple_retry(sock.connect, [(host, port)], max_timeout=timeout)
self.session = ssh2_Session()
self.session.handshake(sock)
if key_filename:
Expand Down
2 changes: 1 addition & 1 deletion broker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def init_settings(settings_path, interactive=False):
validators = [
Validator("HOST_USERNAME", default="root"),
Validator("HOST_PASSWORD", default="toor"),
Validator("HOST_CONNECTION_TIMEOUT", default=None),
Validator("HOST_CONNECTION_TIMEOUT", default=60),
Validator("HOST_SSH_PORT", default=22),
Validator("HOST_SSH_KEY_FILENAME", default=None),
Validator("LOGGING", is_type_of=dict),
Expand Down

0 comments on commit e34979b

Please sign in to comment.