Merge pull request #4701 from hashicorp/phinze/fix-race-winrm
communicator/winrm: fix data race in io copy
This commit is contained in:
commit
1893942732
|
@ -7,6 +7,7 @@ import (
|
|||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/communicator/remote"
|
||||
|
@ -148,10 +149,20 @@ func (c *Communicator) Start(rc *remote.Cmd) error {
|
|||
func runCommand(shell *winrm.Shell, cmd *winrm.Command, rc *remote.Cmd) {
|
||||
defer shell.Close()
|
||||
|
||||
go io.Copy(rc.Stdout, cmd.Stdout)
|
||||
go io.Copy(rc.Stderr, cmd.Stderr)
|
||||
var wg sync.WaitGroup
|
||||
go func() {
|
||||
wg.Add(1)
|
||||
io.Copy(rc.Stdout, cmd.Stdout)
|
||||
wg.Done()
|
||||
}()
|
||||
go func() {
|
||||
wg.Add(1)
|
||||
io.Copy(rc.Stderr, cmd.Stderr)
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
cmd.Wait()
|
||||
wg.Wait()
|
||||
rc.SetExited(cmd.ExitCode())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue