From 8565a30c690a25b491e5383dc8a231c5f05d0940 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 9 Apr 2019 15:29:07 +0200 Subject: [PATCH] TimeoutProvisioner: also display an error log when the context times out --- packer/provisioner_timeout.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 }