provisioners/local-exec: remove data race by setting err only once

This commit is contained in:
Mitchell Hashimoto 2017-01-30 10:21:05 -08:00
parent 3e771a674c
commit 3776d31d69
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 3 additions and 4 deletions

View File

@ -72,15 +72,14 @@ func applyFn(ctx context.Context) error {
err := cmd.Start()
if err == nil {
// Wait for the command to complete in a goroutine
doneCh := make(chan struct{})
doneCh := make(chan error, 1)
go func() {
defer close(doneCh)
err = cmd.Wait()
doneCh <- cmd.Wait()
}()
// Wait for the command to finish or for us to be interrupted
select {
case <-doneCh:
case err = <-doneCh:
case <-ctx.Done():
cmd.Process.Kill()
err = cmd.Wait()