Skip to content

Commit

Permalink
Backport winrm panic workaround (#209)
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke authored Jun 5, 2024
1 parent 2dff216 commit 31b7511
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions winrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,23 @@ type Command struct {
}

// Wait blocks until the command finishes
func (c *Command) Wait() error {
func (c *Command) Wait() (err error) { //nolint:nonamedreturns // needed for panic recovery
defer func() {
if r := recover(); err == nil && r != nil {
if strings.Contains(fmt.Sprint(r), "close of closed channel") {
log.Debugf("recovered from a panic in Command.Wait: %v", r)
} else {
panic(r)
}
}
}()

defer c.sh.Close()
defer c.cmd.Close()

c.wg.Wait()
c.cmd.Wait()
log.Debugf("command finished")
var err error
if c.cmd.ExitCode() != 0 {
err = fmt.Errorf("%w: exit code %d", ErrCommandFailed, c.cmd.ExitCode())
}
Expand Down

0 comments on commit 31b7511

Please sign in to comment.