Merge pull request #4701 from hashicorp/phinze/fix-race-winrm

communicator/winrm: fix data race in io copy
This commit is contained in:
Sander van Harmelen 2016-01-20 20:29:42 +01:00
commit 1893942732
1 changed files with 13 additions and 2 deletions

View File

@ -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())
}