Skip to content

Commit

Permalink
If the websocket fails to connect initially, create a whole new clien… (
Browse files Browse the repository at this point in the history
#42)

* 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)

* Fix lint

* Move the go dnscheck outside the loop
  • Loading branch information
cmmarslender authored Sep 12, 2024
1 parent 3636588 commit 4443020
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,26 @@ 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
}

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())
Expand All @@ -37,17 +50,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 {
err := h.OpenWebsocket()
if err != nil {
log.Println(err.Error())
time.Sleep(5 * time.Second)
continue
}
break
func startWebsocket(h *healthcheck.Healthcheck) error {
err := h.OpenWebsocket()
if err != nil {
return err
}
return nil
}

0 comments on commit 4443020

Please sign in to comment.