Skip to content

Commit

Permalink
roachprod: ensure CommandContext returns when context is canceled
Browse files Browse the repository at this point in the history
Without setting `WaitDelay`, there is a chance that we will hang
waiting for child processes to exit if the IO pipes are not closed.

See documentation at:

https://pkg.go.dev/os/exec#Cmd

Informs: #131095

Release note: None
  • Loading branch information
renatolabs committed Sep 25, 2024
1 parent f5beced commit e6c909b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/roachprod/install/cluster_synced.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ func scpWithRetry(
scpCtx, cancel := context.WithTimeout(ctx, scpTimeout)
defer cancel()

return runWithMaybeRetry(ctx, l, DefaultRetryOpt, defaultSCPShouldRetryFn,
func(ctx context.Context) (*RunResultDetails, error) { return scp(scpCtx, l, src, dest) })
return runWithMaybeRetry(scpCtx, l, DefaultRetryOpt, defaultSCPShouldRetryFn,
func(ctx context.Context) (*RunResultDetails, error) { return scp(ctx, l, src, dest) })
}

// Host returns the public IP of a node.
Expand Down Expand Up @@ -2801,6 +2801,7 @@ func scp(ctx context.Context, l *logger.Logger, src, dest string) (*RunResultDet
args = append(args, sshAuthArgs()...)
args = append(args, src, dest)
cmd := exec.CommandContext(ctx, args[0], args[1:]...)
cmd.WaitDelay = time.Second // make sure the call below returns when the context is canceled

out, err := cmd.CombinedOutput()
if err != nil {
Expand Down

0 comments on commit e6c909b

Please sign in to comment.