Skip to content

Commit

Permalink
Improve winrm channel close panic recovery workaround (#215)
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke authored Aug 6, 2024
1 parent a01379f commit c46cde3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions winrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ func (c *WinRM) Exec(cmd string, opts ...exec.Option) error { //nolint:cyclop

wg.Add(1)
go func() {
// ignore channel close panics
defer func() {
if r := recover(); r != nil {
log.Debugf("recovered from a panic while reading stderr: %v", r)
}
}()
defer wg.Done()
if execOpts.Writer == nil {
outputScanner := bufio.NewScanner(command.Stdout)
Expand All @@ -344,6 +350,12 @@ func (c *WinRM) Exec(cmd string, opts ...exec.Option) error { //nolint:cyclop

wg.Add(1)
go func() {
// ignore channel close panics
defer func() {
if r := recover(); r != nil {
log.Debugf("recovered from a panic while reading stderr: %v", r)
}
}()
defer wg.Done()
outputScanner := bufio.NewScanner(command.Stderr)

Expand Down

0 comments on commit c46cde3

Please sign in to comment.