Compare commits

...

1 Commits

Author SHA1 Message Date
a-kenji
fa170a6476 pkgs/clan: Fix clan ssh subcommand
Fix a regression in the `clan ssh` subcommand, which incorrectly assumed
that every target host without a `:` inside can't ever be an ipv6
address.

We now try to reach the default remote port on both protocols, while
this is not a completely robust solution, this doesn't make any assumptions
of the address family based on arbitrary host names anymore, which
should alleviate many problems with the introduced regression.

The PR that introduced the ssh regression #2604 notably did
not describe why this change was made, which makes understanding the
motivation not very easy.

Alternatives:
- Use an actual ssh implementation (This can also be done later in a
  follow up) - this has the benefit that ssh configuration is
  propagated at the cost of complexity
- Add tests for this feature -> this would need to run in a VM test as I
  understand it currently
2025-06-24 16:16:25 +02:00

View File

@@ -467,16 +467,18 @@ def is_ssh_reachable(remote: Remote, opts: ConnectionOptions | None = None) -> b
if opts is None:
opts = ConnectionOptions()
address_family = socket.AF_INET6 if ":" in remote.address else socket.AF_INET
address_families = [socket.AF_INET, socket.AF_INET6]
for _ in range(opts.retries):
with socket.socket(address_family, socket.SOCK_STREAM) as sock:
sock.settimeout(opts.timeout)
try:
sock.connect((remote.address, remote.port or 22))
return True
except (TimeoutError, OSError):
pass
else:
time.sleep(opts.timeout)
for address_family in address_families:
with socket.socket(address_family, socket.SOCK_STREAM) as sock:
sock.settimeout(opts.timeout)
try:
sock.connect((remote.address, remote.port or 22))
except (TimeoutError, OSError):
continue
else:
return True
time.sleep(opts.timeout)
return False