Skip to content

Commit

Permalink
feat: add context to ssh execution
Browse files Browse the repository at this point in the history
  • Loading branch information
d-strobel committed Oct 15, 2023
1 parent c40c785 commit 645caab
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions connection/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ func (c *Connection) runSSH(ctx context.Context, cmd string) (string, string, er
return "", "", err
}

// Wait for the command to complete
err = s.Wait()
// Wait for the command to complete with context support
select {
case <-ctx.Done():
_ = s.Signal(ssh.SIGINT)
return "", "", ctx.Err()
default:
err = s.Wait()
}

// Return the error if stderr has no value
if err != nil && stderrBytes == nil {
Expand Down

0 comments on commit 645caab

Please sign in to comment.