Skip to content

Commit

Permalink
provisioner/remote-exec: Move script cleanup after command wait
Browse files Browse the repository at this point in the history
The script cleanup step added in #5577 was positioned before the
`cmd.Wait()` call to ensure the command completes. This was causing
non-deterministic failures, especially for longer running scripts.

Fixes #5699
Fixes #5737
  • Loading branch information
phinze committed Mar 21, 2016
1 parent f803c81 commit 0b7e1fa
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions builtin/provisioners/remote-exec/resource_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ func (p *ResourceProvisioner) runScripts(
go p.copyOutput(o, outR, outDoneCh)
go p.copyOutput(o, errR, errDoneCh)

remotePath := comm.ScriptPath()
err = retryFunc(comm.Timeout(), func() error {
remotePath := comm.ScriptPath()

if err := comm.UploadScript(remotePath, script); err != nil {
return fmt.Errorf("Failed to upload script: %v", err)
Expand All @@ -192,13 +192,6 @@ func (p *ResourceProvisioner) runScripts(
return fmt.Errorf("Error starting script: %v", err)
}

// Upload a blank follow up file in the same path to prevent residual
// script contents from remaining on remote machine
empty := bytes.NewReader([]byte(""))
if err := comm.Upload(remotePath, empty); err != nil {
return fmt.Errorf("Failed to upload empty follow up script: %v", err)
}

return nil
})
if err == nil {
Expand All @@ -214,6 +207,14 @@ func (p *ResourceProvisioner) runScripts(
<-outDoneCh
<-errDoneCh

// Upload a blank follow up file in the same path to prevent residual
// script contents from remaining on remote machine
empty := bytes.NewReader([]byte(""))
if err := comm.Upload(remotePath, empty); err != nil {
// This feature is best-effort.
log.Printf("[WARN] Failed to upload empty follow up script: %v", err)
}

// If we have an error, return it out now that we've cleaned up
if err != nil {
return err
Expand Down

0 comments on commit 0b7e1fa

Please sign in to comment.