lib.ec.ssh.Paramiko: Fix URI parameters, stdin handling, and output deadlock #85
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/fix/20260905-lib-ec-ssh-paramiko-fix-uri-parameters-stdin-handling-and-output-deadlock"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR adds three independent fixes to the Paramiko SSH client, each addressing a defect that makes remote commands fail or hang:
lib.ec.ssh.Paramiko: Pass port and password
__client() connects using only the URI's hostname and username. The URI's port is ignored, so ssh://host:2222/... ends up connecting to port 22, and a password carried in the URI is never passed to paramiko, so URI-based password authentication cannot work. The Exec and AsyncSSH clients both honor the port and the password.
Pass the port and the password to connect(). The port argument is omitted entirely when the URI carries no port, because getaddrinfo() would interpret a None port as service port 0; without the argument, paramiko falls back to its default of 22.
lib.ec.ssh.Paramiko: Close remote stdin
_run_ssh() writes cmd_input to the remote stdin channel but never closes the write side. The channel stays open until the client process exits, so a remote command that reads stdin (cat, a login shell, ...) never sees EOF and blocks forever - including for cmd_input = None, which is supposed to mean non-interactive with stdin from /dev/null.
Call shutdown_write() on the channel after writing the input, or immediately when there is none, so the remote command gets EOF.
lib.ec.ssh.Paramiko: Avoid recv deadlock
_run_ssh() waits for the remote process's exit status before reading stdout and stderr. When a command produces more output than the channel's flow-control window can hold, the server stops sending, the remote process blocks on its write and never exits, and recv_exit_status() blocks forever.
Drain stdout and stderr to EOF first - the channels close when the process exits, so reading them also implies completion - and only then query the exit status.