From de12d568cee48fb34c697d4ae08a634039f363c6 Mon Sep 17 00:00:00 2001 From: M09Ic Date: Fri, 1 Nov 2024 12:30:35 +0800 Subject: [PATCH] enhance: add hard exit, https://github.com/chainreactors/spray/issues/78 --- cmd/cmd.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/cmd.go b/cmd/cmd.go index fcf3138..2029c77 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -149,6 +149,15 @@ func Spray() { } ctx, canceler := context.WithTimeout(context.Background(), time.Duration(runner.Deadline)*time.Second) + go func() { + select { + case <-ctx.Done(): + time.Sleep(10 * time.Second) + logs.Log.Errorf("deadline and timeout not work, hard exit!!!") + os.Exit(0) + } + }() + go func() { exitChan := make(chan os.Signal, 2) signal.Notify(exitChan, os.Interrupt, syscall.SIGTERM)