Skip to content

Commit

Permalink
Merge pull request #309 from cfergeau/sshrace
Browse files Browse the repository at this point in the history
ssh: Recreate connection on retries in setupProxy
  • Loading branch information
openshift-merge-bot[bot] authored Jan 16, 2024
2 parents 8912b78 + feda120 commit f20bbe0
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions pkg/sshclient/ssh_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,11 @@ 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")
Expand Down Expand Up @@ -215,13 +214,6 @@ 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 {
Expand Down

0 comments on commit f20bbe0

Please sign in to comment.