From 1a0b6a7a44b59f5b868172b7dceb41132cdfeced Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 12 Aug 2024 17:28:32 +0200 Subject: [PATCH] cli/connhelper: getConnectionHelper: move ssh-option funcs out of closure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The addSSHTimeout and disablePseudoTerminalAllocation were added in commits a5ebe2282aabaf983c116525af4a7c5eeedf2c6e and f3c2c26b1025f3e785f142fbd8ebed5cf8265f44, and called inside the Dialer function, which means they're called every time the Dialer is called. Given that the sshFlags slice is not mutated by the Dialer, we can call these functions once. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 0fd3fb08405c2ffa33ecd1c368fe8e20f2df4053) Signed-off-by: Paweł Gronowski --- cli/connhelper/connhelper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/connhelper/connhelper.go b/cli/connhelper/connhelper.go index ab83ee2920..152d3e2953 100644 --- a/cli/connhelper/connhelper.go +++ b/cli/connhelper/connhelper.go @@ -45,14 +45,14 @@ func getConnectionHelper(daemonURL string, sshFlags []string) (*ConnectionHelper if err != nil { return nil, errors.Wrap(err, "ssh host connection is not valid") } + sshFlags = addSSHTimeout(sshFlags) + sshFlags = disablePseudoTerminalAllocation(sshFlags) return &ConnectionHelper{ Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) { args := []string{"docker"} if sp.Path != "" { args = append(args, "--host", "unix://"+sp.Path) } - sshFlags = addSSHTimeout(sshFlags) - sshFlags = disablePseudoTerminalAllocation(sshFlags) args = append(args, "system", "dial-stdio") return commandconn.New(ctx, "ssh", append(sshFlags, sp.Args(args...)...)...) },