From cad9899cfb7c21bec3460d816c1648d4f2c75cbe Mon Sep 17 00:00:00 2001 From: Mark Peek Date: Wed, 14 Oct 2015 09:08:39 -0700 Subject: [PATCH] communicator/winrm: call wg.Add() before running goroutine --- communicator/winrm/communicator.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/communicator/winrm/communicator.go b/communicator/winrm/communicator.go index 8530ad82b..54dcfb48d 100644 --- a/communicator/winrm/communicator.go +++ b/communicator/winrm/communicator.go @@ -88,18 +88,19 @@ func runCommand(shell *winrm.Shell, cmd *winrm.Command, rc *packer.RemoteCmd) { var wg sync.WaitGroup copyFunc := func(w io.Writer, r io.Reader) { - wg.Add(1) defer wg.Done() io.Copy(w, r) } if rc.Stdout != nil && cmd.Stdout != nil { + wg.Add(1) go copyFunc(rc.Stdout, cmd.Stdout) } else { log.Printf("[WARN] Failed to read stdout for command '%s'", rc.Command) } if rc.Stderr != nil && cmd.Stderr != nil { + wg.Add(1) go copyFunc(rc.Stderr, cmd.Stderr) } else { log.Printf("[WARN] Failed to read stderr for command '%s'", rc.Command)