TimeoutProvisioner: also display an error log when the context times out

This commit is contained in:
Adrien Delorme 2019-04-09 15:29:07 +02:00
parent 6ff392d713
commit 8565a30c69
1 changed files with 21 additions and 1 deletions

View File

@ -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
}