diff --git a/packer/provisioner_timeout.go b/packer/provisioner_timeout.go index a2af71e7a..1da02f563 100644 --- a/packer/provisioner_timeout.go +++ b/packer/provisioner_timeout.go @@ -19,5 +19,25 @@ func (p *TimeoutProvisioner) Provision(ctx context.Context, ui Ui, comm Communic // Use a select to determine if we get cancelled during the wait ui.Say(fmt.Sprintf("Setting a %s timeout for the next provisioner...", p.Timeout)) - return p.Provisioner.Provision(ctx, ui, comm) + + errC := make(chan interface{}) + + go func() { + select { + case <-errC: + // all good + case <-ctx.Done(): + switch ctx.Err() { + case context.DeadlineExceeded: + ui.Error("Cancelling provisioner after a timeout...") + default: + // the context also gets cancelled when the provisioner is + // successful + } + } + }() + + err := p.Provisioner.Provision(ctx, ui, comm) + close(errC) + return err }