From af132a186d1525724682bd99c6c9616a7582f1b6 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 15 Mar 2018 12:25:44 -0400 Subject: [PATCH] remove timeout from remote-exec command context The timeout for the remote command was taken from the wrong config field, and the connection timeout was being used which is 5 min. Any remote command taking more than 5 min would be terminated by disconnecting the communicator. Remove the timeout from the context, and rely on the global timeout provided by terraform. There was no way to get the error from the communicator previously, so the broken connection was silently ignored and the provisioner returned successfully. Now we can use the new cmd.Err() method to retrieve any errors encountered during execution. --- .../remote-exec/resource_provisioner.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/builtin/provisioners/remote-exec/resource_provisioner.go b/builtin/provisioners/remote-exec/resource_provisioner.go index 378a282ed7..8c3d671b9a 100644 --- a/builtin/provisioners/remote-exec/resource_provisioner.go +++ b/builtin/provisioners/remote-exec/resource_provisioner.go @@ -156,10 +156,6 @@ func runScripts( o terraform.UIOutput, comm communicator.Communicator, scripts []io.ReadCloser) error { - // Wrap out context in a cancelation function that we use to - // kill the connection. - ctx, cancelFunc := context.WithTimeout(ctx, comm.Timeout()) - defer cancelFunc() // Wait for the context to end and then disconnect go func() { @@ -200,10 +196,14 @@ func runScripts( if err := comm.Start(cmd); err != nil { return fmt.Errorf("Error starting script: %v", err) } - cmd.Wait() - if cmd.ExitStatus != 0 { - err = fmt.Errorf("Script exited with non-zero exit status: %d", cmd.ExitStatus) + + if err := cmd.Err(); err != nil { + return fmt.Errorf("Remote command exited with error: %s", err) + } + + if cmd.ExitStatus() != 0 { + err = fmt.Errorf("Script exited with non-zero exit status: %d", cmd.ExitStatus()) } // Upload a blank follow up file in the same path to prevent residual