From 54034689ef8fc37f6fc05b7a5b4918152284ea1c Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 25 Jul 2019 16:32:16 -0700 Subject: [PATCH] On abort, return gracefully rather than exiting so that the subprocess doesn't unexpectedly disconnect from the parent and cause a confusing EOF error in the logs --- common/multistep_runner.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/common/multistep_runner.go b/common/multistep_runner.go index b34ee3a04..0ccc4d349 100644 --- a/common/multistep_runner.go +++ b/common/multistep_runner.go @@ -71,17 +71,29 @@ func (s abortStep) Run(ctx context.Context, state multistep.StateBag) multistep. } func (s abortStep) Cleanup(state multistep.StateBag) { + _, alreadyLogged := state.GetOk("abort_step_logged") err, ok := state.GetOk("error") - if ok { + if ok && !alreadyLogged { s.ui.Error(fmt.Sprintf("%s", err)) + state.Put("abort_step_logged", true) } if _, ok := state.GetOk(multistep.StateCancelled); ok { - s.ui.Error("Interrupted, aborting...") - os.Exit(1) + if !alreadyLogged { + s.ui.Error("Interrupted, aborting...") + state.Put("abort_step_logged", true) + } else { + s.ui.Error(fmt.Sprintf("aborted: skipping cleanup of step %q", typeName(s.step))) + } + return } if _, ok := state.GetOk(multistep.StateHalted); ok { - s.ui.Error(fmt.Sprintf("Step %q failed, aborting...", typeName(s.step))) - os.Exit(1) + if !alreadyLogged { + s.ui.Error(fmt.Sprintf("Step %q failed, aborting...", typeName(s.step))) + state.Put("abort_step_logged", true) + } else { + s.ui.Error(fmt.Sprintf("aborted: skipping cleanup of step %q", typeName(s.step))) + } + return } s.step.Cleanup(state) }