From 069c36e564a647f66060f825d967ef7b4e1f3452 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Tue, 16 Jan 2024 10:39:30 +0100 Subject: [PATCH] Revert "ssh: Recreate connection on retries in setupProxy" This reverts commit feda1204406175648ea5a9cca7df3cab197ec7be. --- pkg/sshclient/ssh_forwarder.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/sshclient/ssh_forwarder.go b/pkg/sshclient/ssh_forwarder.go index b994f24d9..75c43991d 100644 --- a/pkg/sshclient/ssh_forwarder.go +++ b/pkg/sshclient/ssh_forwarder.go @@ -166,11 +166,12 @@ func setupProxy(ctx context.Context, socketURI *url.URL, dest *url.URL, identity return conn, err } + conn, err := initialConnection(ctx, connectFunc) + if err != nil { + return &SSHForward{}, err + } + createBastion := func() (*Bastion, error) { - conn, err := connectFunc(ctx, nil) - if err != nil { - return nil, err - } return CreateBastion(dest, passphrase, identity, conn, connectFunc) } bastion, err := retry(ctx, createBastion, "Waiting for sshd") @@ -214,6 +215,13 @@ loop: return returnVal, fmt.Errorf("timeout: %w", err) } +func initialConnection(ctx context.Context, connectFunc ConnectCallback) (net.Conn, error) { + retryFunc := func() (net.Conn, error) { + return connectFunc(ctx, nil) + } + return retry(ctx, retryFunc, "Waiting for sshd socket") +} + func acceptConnection(ctx context.Context, listener net.Listener, bastion *Bastion, socketURI *url.URL) error { con, err := listener.Accept() if err != nil {