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

Added timeout to SSHConnector #644

Merged
merged 2 commits into from
Feb 10, 2025
Merged

Added timeout to SSHConnector #644

merged 2 commits into from
Feb 10, 2025

Conversation

LanderOtto
Copy link
Collaborator

@LanderOtto LanderOtto commented Jan 20, 2025

This commit adds the timeout in the asyncssh.connect() call. The user chooses the time to wait using the connectTimeout option.

Updated documentation checksum because the connectTimeout option was added in the SSHConnector schema

@LanderOtto LanderOtto marked this pull request as draft January 20, 2025 18:08
Copy link

codecov bot commented Jan 20, 2025

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 71.41%. Comparing base (b5ab2f8) to head (22aa629).
Report is 2 commits behind head on master.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
streamflow/deployment/connector/ssh.py 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #644      +/-   ##
==========================================
- Coverage   71.44%   71.41%   -0.04%     
==========================================
  Files          88       88              
  Lines       11345    11349       +4     
  Branches     1981     1982       +1     
==========================================
- Hits         8106     8105       -1     
- Misses       2785     2788       +3     
- Partials      454      456       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@LanderOtto LanderOtto force-pushed the feat/ssh-timeout branch 4 times, most recently from 6333375 to 2ba9820 Compare January 24, 2025 16:26
@LanderOtto LanderOtto marked this pull request as ready for review February 6, 2025 01:02
raise
if isinstance(err, asyncio.TimeoutError):
raise asyncio.TimeoutError(
f"The SSH connection attempt to {self.get_hostname()} took too long."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
f"The SSH connection attempt to {self.get_hostname()} took too long."
f"SSH connection to {self.get_hostname()} failed: connection timed out"

@@ -70,6 +70,11 @@
"description": "Perform a strict validation of the host SSH keys (and return exception if key is not recognized as valid)",
"default": true
},
"connectTimeout": {
"type": "integer",
"description": "Time (in seconds) to wait for establish the connection. When an attempt fails, the time to wait is increased.",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"description": "Time (in seconds) to wait for establish the connection. When an attempt fails, the time to wait is increased.",
"description": "Max time (in seconds) to wait for establishing an SSH connection.",

@@ -83,6 +83,7 @@ async def _get_connection(
port=port,
tunnel=await self._get_connection(config.tunnel),
username=config.username,
connect_timeout=config.connect_timeout * (self.connection_attempts + 1),
Copy link
Member

Choose a reason for hiding this comment

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

I think the timeout can be left constant.

Comment on lines 553 to 557
connect_timeout=(
node["connect_timeout"]
if "connect_timeout" in node
else self.connect_timeout
),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
connect_timeout=(
node["connect_timeout"]
if "connect_timeout" in node
else self.connect_timeout
),
connect_timeout=node.get("connect_timeout", self.connect_timeout),

…er chooses the time to wait using the `connectTimeout` option. If the `retry` is enabled, the time to wait is increased at each attempt.

Updated documentation checksum because the `connectTimeout` option was added in the `SSHConnector` schema
@@ -83,6 +83,7 @@ async def _get_connection(
port=port,
tunnel=await self._get_connection(config.tunnel),
username=config.username,
connect_timeout=config.connect_timeout * self.connection_attempts,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
connect_timeout=config.connect_timeout * self.connection_attempts,
connect_timeout=config.connect_timeout,

Copy link
Member

Choose a reason for hiding this comment

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

I think the timeout can be left constant.

@LanderOtto LanderOtto force-pushed the feat/ssh-timeout branch 3 times, most recently from 19062e9 to 6a46771 Compare February 8, 2025 17:34
@GlassOfWhiskey GlassOfWhiskey merged commit 99c062a into master Feb 10, 2025
32 checks passed
@GlassOfWhiskey GlassOfWhiskey deleted the feat/ssh-timeout branch February 10, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants