Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom socket connect timeout in Session() #210

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions broker/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def connect(
password=password,
port=_port,
key_filename=key_filename,
timeout=timeout
Copy link
Contributor Author

@akhil-jha akhil-jha May 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependent on settings.HOST_CONNECTION_TIMEOUT. If not , it'll be none. That means no retry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If None, simple_retry should still get your default of 60 so I think we're good here!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right.okay yes.

)

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 @@ -31,7 +31,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),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you want to keep it? or should I remove it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try to keep this version, but we'll need to pay attention to automation after this release is live.

Validator("HOST_SSH_PORT", default=22),
Validator("HOST_SSH_KEY_FILENAME", default=None),
Validator("LOGGING", is_type_of=dict),
Expand Down