Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ func (p *Provisioner) resetConnection() error {
func (p *Provisioner) provision() error {
var err error

// Close existing client before creating new connection
if p.Client != nil {
_ = p.Client.Close()
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SSH client close logic here differs from the pattern used in resetConnection() and waitForNodeReboot(). Those functions check if the connection is still alive by attempting to create a session before closing. Consider using the same pattern here for consistency:

if p.Client != nil {
    session, err := p.Client.NewSession()
    if err == nil {
        _ = session.Close()
        if err := p.Client.Close(); err != nil {
            return fmt.Errorf("failed to close ssh client: %w", err)
        }
    }
    p.Client = nil
}

This prevents potential issues with closing already-dead connections and follows the established convention in the codebase.

Suggested change
_ = p.Client.Close()
// Try to create a new session to check if connection is alive
session, err := p.Client.NewSession()
if err == nil {
_ = session.Close()
// Connection is alive, close it
if err := p.Client.Close(); err != nil {
return fmt.Errorf("failed to close ssh client: %w", err)
}
}
// If we get here, either the connection was already closed or we couldn't create a session

Copilot uses AI. Check for mistakes.
p.Client = nil
}

// Create a new ssh connection
p.Client, err = connectOrDie(p.KeyPath, p.UserName, p.HostUrl)
if err != nil {
Expand Down Expand Up @@ -259,6 +265,7 @@ func (p *Provisioner) provision() error {

_ = writer.Close()
wg.Wait()
_ = reader.Close()

select {
case copyErr := <-copyErrCh:
Expand Down
Loading