From 3776d31d6981493a41a59651bdd1137c16ce3b0f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 30 Jan 2017 10:21:05 -0800 Subject: [PATCH] provisioners/local-exec: remove data race by setting err only once --- builtin/provisioners/local-exec/resource_provisioner.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/builtin/provisioners/local-exec/resource_provisioner.go b/builtin/provisioners/local-exec/resource_provisioner.go index 86f27fb35..0ac2f83c0 100644 --- a/builtin/provisioners/local-exec/resource_provisioner.go +++ b/builtin/provisioners/local-exec/resource_provisioner.go @@ -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()