From f19b65abe19e33638335368274dd4e6c5a18892f Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Wed, 11 Sep 2024 21:00:32 -0500 Subject: [PATCH 1/3] If the websocket fails to connect initially, create a whole new client (so certs are reloaded) in case we have the wrong certs (this solves an edge case in operator where we grab certs between inits) --- cmd/serve.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index 9d133b4..3ac5e86 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -20,15 +20,27 @@ var serveCmd = &cobra.Command{ log.Fatalf("Error parsing log level: %s\n", err.Error()) } - h, err := healthcheck.NewHealthcheck(uint16(viper.GetInt("healthcheck-port")), level) - if err != nil { - log.Fatalln(err.Error()) + var h *healthcheck.Healthcheck + + // Loop until we get a connection or cancel + // It just retries every 5 seconds to connect to the RPC server until it succeeds or the app is stopped + for { + h, err = healthcheck.NewHealthcheck(uint16(viper.GetInt("healthcheck-port")), level) + if err != nil { + log.Fatalln(err.Error()) + } + + err = startWebsocket(h) + if err != nil { + log.Printf("error starting websocket. Creating new client and trying again in 5 seconds: %s\n", err.Error()) + time.Sleep(5 * time.Second) + continue + } + + go h.DNSCheckLoop() + break } - // Run this in the background, so the metrics healthz endpoint can come up while waiting for Chia - go startWebsocket(h) - go h.DNSCheckLoop() - log.Fatalln(h.StartServer()) }, } @@ -37,17 +49,10 @@ func init() { rootCmd.AddCommand(serveCmd) } -func startWebsocket(h *healthcheck.Healthcheck) { - // Loop until we get a connection or cancel - // This enables starting the healthcheck app even if the chia RPC service is not up/responding - // It just retries every 5 seconds to connect to the RPC server until it succeeds or the app is stopped - for { +func startWebsocket(h *healthcheck.Healthcheck) error { err := h.OpenWebsocket() if err != nil { - log.Println(err.Error()) - time.Sleep(5 * time.Second) - continue + return err } - break - } + return nil } From cc1f91e25e2ba006b82776c09fe1b11066e56853 Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Wed, 11 Sep 2024 21:02:27 -0500 Subject: [PATCH 2/3] Fix lint --- cmd/serve.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index 3ac5e86..9f9885c 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -50,9 +50,9 @@ func init() { } func startWebsocket(h *healthcheck.Healthcheck) error { - err := h.OpenWebsocket() - if err != nil { - return err - } - return nil + err := h.OpenWebsocket() + if err != nil { + return err + } + return nil } From 578bbf9c8de42eed03e0877df9331f8451d4cfe8 Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Wed, 11 Sep 2024 21:08:03 -0500 Subject: [PATCH 3/3] Move the go dnscheck outside the loop --- cmd/serve.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/serve.go b/cmd/serve.go index 9f9885c..010426c 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -37,10 +37,11 @@ var serveCmd = &cobra.Command{ continue } - go h.DNSCheckLoop() break } + go h.DNSCheckLoop() + log.Fatalln(h.StartServer()) }, }