From c83e10996dd65c6a3bf0ffdbf9c1bc8b2123e2c8 Mon Sep 17 00:00:00 2001 From: andig Date: Sat, 29 Oct 2022 16:16:45 +0200 Subject: [PATCH] Fix reboot delay in case of error --- cmd/root.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 72c398a2b..64ca03b6d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -25,7 +25,7 @@ import ( "github.com/spf13/viper" ) -const rebootDelay = 5 * time.Minute // delayed reboot on error +const rebootDelay = 5 * time.Second // delayed reboot on error var ( log = util.NewLogger("main") @@ -229,10 +229,15 @@ func runRoot(cmd *cobra.Command, args []string) { }) }) + publishErrorInfo(valueChan, cfgFile, err) + log.FATAL.Println(err) log.FATAL.Printf("will attempt restart in: %v", rebootDelay) - publishErrorInfo(valueChan, cfgFile, err) + once.Do(func() { + <-time.After(rebootDelay) + close(stopC) // signal loop to end + }) } // uds health check listener @@ -242,14 +247,9 @@ func runRoot(cmd *cobra.Command, args []string) { go func() { <-stopC - timeout := conf.Interval - if err != nil { - timeout = rebootDelay - } - select { case <-shutdownDoneC(): // wait for shutdown - case <-time.After(timeout): + case <-time.After(conf.Interval): } if err != nil {