diff --git a/cmd/cloud.go b/cmd/cloud.go index 59e9d0a85a69..ad0f4be69cf5 100644 --- a/cmd/cloud.go +++ b/cmd/cloud.go @@ -200,10 +200,10 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { globalCancel() }() } - hardStop := func(sig os.Signal) { + onHardStop := func(sig os.Signal) { logger.WithField("sig", sig).Error("Aborting k6 in response to signal, we won't wait for the test to end.") } - stopSignalHandling := handleTestAbortSignals(c.gs, gracefulStop, hardStop) + stopSignalHandling := handleTestAbortSignals(c.gs, gracefulStop, onHardStop) defer stopSignalHandling() et, err := lib.NewExecutionTuple(test.derivedConfig.ExecutionSegment, test.derivedConfig.ExecutionSegmentSequence) diff --git a/cmd/common.go b/cmd/common.go index 5d39fd950bdb..47e515552708 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -92,7 +92,7 @@ func printToStdout(gs *globalState, s string) { } // Trap Interrupts, SIGINTs and SIGTERMs and call the given. -func handleTestAbortSignals(gs *globalState, firstHandler, secondHandler func(os.Signal)) (stop func()) { +func handleTestAbortSignals(gs *globalState, gracefulStopHandler, onHardStop func(os.Signal)) (stop func()) { sigC := make(chan os.Signal, 2) done := make(chan struct{}) gs.signalNotify(sigC, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) @@ -100,15 +100,15 @@ func handleTestAbortSignals(gs *globalState, firstHandler, secondHandler func(os go func() { select { case sig := <-sigC: - firstHandler(sig) + gracefulStopHandler(sig) case <-done: return } select { case sig := <-sigC: - if secondHandler != nil { - secondHandler(sig) + if onHardStop != nil { + onHardStop(sig) } // If we get a second signal, we immediately exit, so something like // https://github.com/k6io/k6/issues/971 never happens again diff --git a/cmd/run.go b/cmd/run.go index 2e868fcd4489..fe2f9eb60e33 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -177,11 +177,11 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) error { logger.WithField("sig", sig).Debug("Stopping k6 in response to signal...") lingerCancel() // stop the test run, metric processing is cancelled below } - hardStop := func(sig os.Signal) { + onHardStop := func(sig os.Signal) { logger.WithField("sig", sig).Error("Aborting k6 in response to signal") globalCancel() // not that it matters, given the following command... } - stopSignalHandling := handleTestAbortSignals(c.gs, gracefulStop, hardStop) + stopSignalHandling := handleTestAbortSignals(c.gs, gracefulStop, onHardStop) defer stopSignalHandling() // Initialize the engine