Skip to content

Commit

Permalink
Merge #124721
Browse files Browse the repository at this point in the history
124721: roachprod: fix check for errors in `find-ports` r=srosenberg,herkolategan a=renatolabs

When finding ports, we only check for the `err` return value from `runCmdOnSingleNode`. However, that function only returns an error if there is a string expansion error. For command errors, the caller needs to check `res.Err`, which was not happening before.

Informs: #124715

Co-authored-by: Renato Costa <[email protected]>
  • Loading branch information
craig[bot] and renatolabs committed May 29, 2024
2 parents 108c66b + 21e229d commit 604bb00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pkg/roachprod/install/cluster_synced.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,14 +1146,20 @@ func defaultCmdOpts(debugName string) RunCmdOptions {
// - specifying the stdin, stdout, and stderr streams
// - specifying the remote session options
// - whether the command should be run with the ROACHPROD env variable (true for all user commands)
//
// NOTE: do *not* return a `nil` `*RunResultDetails` in this function:
// we want to support callers being able to use
// `errors.CombineErrors(err, res.Err)` when they don't care about the
// origin of the error.
func (c *SyncedCluster) runCmdOnSingleNode(
ctx context.Context, l *logger.Logger, node Node, cmd string, opts RunCmdOptions,
) (*RunResultDetails, error) {
var noResult RunResultDetails
// Argument template expansion is node specific (e.g. for {store-dir}).
e := expander{node: node}
expandedCmd, err := e.expand(ctx, l, c, cmd)
if err != nil {
return nil, errors.WithDetailf(err, "error expanding command: %s", cmd)
return &noResult, errors.WithDetailf(err, "error expanding command: %s", cmd)
}

nodeCmd := expandedCmd
Expand Down
4 changes: 2 additions & 2 deletions pkg/roachprod/install/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ func (c *SyncedCluster) FindOpenPorts(
}

res, err := c.runCmdOnSingleNode(ctx, l, node, buf.String(), defaultCmdOpts("find-ports"))
if err != nil {
return nil, transientFailure(errors.Wrapf(err, "output:\n%s", res.CombinedOut))
if findPortsErr := errors.CombineErrors(err, res.Err); findPortsErr != nil {
return nil, transientFailure(errors.Wrapf(findPortsErr, "output:\n%s", res.CombinedOut))
}
ports, err = stringToIntegers(strings.TrimSpace(res.CombinedOut))
if err != nil {
Expand Down

0 comments on commit 604bb00

Please sign in to comment.