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

SSH connection is not being reused when sending multiple commands #2966

Open
VelorumS opened this issue Mar 22, 2022 · 0 comments · May be fixed by #2970 or #3174
Open

SSH connection is not being reused when sending multiple commands #2966

VelorumS opened this issue Mar 22, 2022 · 0 comments · May be fixed by #2970 or #3174

Comments

@VelorumS
Copy link

cmds.sh connects through SSH and executes several commands:

#!/usr/bin/env python3

import docker


if __name__ == "__main__":
    client = docker.DockerClient("ssh://localhost", use_ssh_client=True)
    client.ping()
    client.images.list()
    client.containers.list()

Running this script spawns a new ssh connection for each command which takes a lot of time because the whole login sequence is repeated:

$ strace -fs256 ./cmds.py 2>&1 | grep exec.*ssh
[pid 35337] execve("/bin/sh", ["/bin/sh", "-c", "ssh -p 22 -- localhost docker system dial-stdio"], 0x14d3a90 /* 72 vars */ <unfinished ...>
[pid 35338] execve("/usr/bin/ssh", ["ssh", "-p", "22", "--", "localhost", "docker", "system", "dial-stdio"], 0x561272c46448 /* 72 vars */ <unfinished ...>
[pid 35405] execve("/bin/sh", ["/bin/sh", "-c", "ssh -p 22 -- localhost docker system dial-stdio"], 0x14d8090 /* 72 vars */ <unfinished ...>
[pid 35406] execve("/usr/bin/ssh", ["ssh", "-p", "22", "--", "localhost", "docker", "system", "dial-stdio"], 0x55c16b5e1448 /* 72 vars */ <unfinished ...>
[pid 35465] execve("/bin/sh", ["/bin/sh", "-c", "ssh -p 22 -- localhost docker system dial-stdio"], 0x14d8090 /* 72 vars */ <unfinished ...>
[pid 35466] execve("/usr/bin/ssh", ["ssh", "-p", "22", "--", "localhost", "docker", "system", "dial-stdio"], 0x55c40c8e4448 /* 72 vars */ <unfinished ...>
[pid 35524] execve("/bin/sh", ["/bin/sh", "-c", "ssh -p 22 -- localhost docker system dial-stdio"], 0x14d8090 /* 72 vars */ <unfinished ...>
[pid 35525] execve("/usr/bin/ssh", ["ssh", "-p", "22", "--", "localhost", "docker", "system", "dial-stdio"], 0x55ae78291448 /* 72 vars */ <unfinished ...>
[pid 35583] execve("/bin/sh", ["/bin/sh", "-c", "ssh -p 22 -- localhost docker system dial-stdio"], 0x14dcfd0 /* 72 vars */ <unfinished ...>
[pid 35584] execve("/usr/bin/ssh", ["ssh", "-p", "22", "--", "localhost", "docker", "system", "dial-stdio"], 0x55b6878d6448 /* 72 vars */ <unfinished ...>
[pid 35642] execve("/bin/sh", ["/bin/sh", "-c", "ssh -p 22 -- localhost docker system dial-stdio"], 0x14dabc0 /* 72 vars */ <unfinished ...>
[pid 35643] execve("/usr/bin/ssh", ["ssh", "-p", "22", "--", "localhost", "docker", "system", "dial-stdio"], 0x562746674448 /* 72 vars */ <unfinished ...>
[pid 35702] execve("/bin/sh", ["/bin/sh", "-c", "ssh -p 22 -- localhost docker system dial-stdio"], 0x14d8090 /* 72 vars */ <unfinished ...>
[pid 35703] execve("/usr/bin/ssh", ["ssh", "-p", "22", "--", "localhost", "docker", "system", "dial-stdio"], 0x555dd2d9a448 /* 72 vars */ <unfinished ...>

I expected it to reuse the same pipe for all commands.

Even using the paramiko client (use_ssh_client=False) seems to be similar because SSHConnectionPool are created for every URL. Those URLs are different for every request.

So I don't really understand how this was supposed to work efficiently. Is there something fundamental that precludes the reuse of the SSH connection?

@VelorumS VelorumS linked a pull request Mar 23, 2022 that will close this issue
@coolbreeze2 coolbreeze2 linked a pull request Sep 4, 2023 that will close this issue
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 a pull request may close this issue.

1 participant