Skip to content

Commit f19b65a

Browse files
committed
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)
1 parent 3636588 commit f19b65a

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

cmd/serve.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,27 @@ var serveCmd = &cobra.Command{
2020
log.Fatalf("Error parsing log level: %s\n", err.Error())
2121
}
2222

23-
h, err := healthcheck.NewHealthcheck(uint16(viper.GetInt("healthcheck-port")), level)
24-
if err != nil {
25-
log.Fatalln(err.Error())
23+
var h *healthcheck.Healthcheck
24+
25+
// Loop until we get a connection or cancel
26+
// It just retries every 5 seconds to connect to the RPC server until it succeeds or the app is stopped
27+
for {
28+
h, err = healthcheck.NewHealthcheck(uint16(viper.GetInt("healthcheck-port")), level)
29+
if err != nil {
30+
log.Fatalln(err.Error())
31+
}
32+
33+
err = startWebsocket(h)
34+
if err != nil {
35+
log.Printf("error starting websocket. Creating new client and trying again in 5 seconds: %s\n", err.Error())
36+
time.Sleep(5 * time.Second)
37+
continue
38+
}
39+
40+
go h.DNSCheckLoop()
41+
break
2642
}
2743

28-
// Run this in the background, so the metrics healthz endpoint can come up while waiting for Chia
29-
go startWebsocket(h)
30-
go h.DNSCheckLoop()
31-
3244
log.Fatalln(h.StartServer())
3345
},
3446
}
@@ -37,17 +49,10 @@ func init() {
3749
rootCmd.AddCommand(serveCmd)
3850
}
3951

40-
func startWebsocket(h *healthcheck.Healthcheck) {
41-
// Loop until we get a connection or cancel
42-
// This enables starting the healthcheck app even if the chia RPC service is not up/responding
43-
// It just retries every 5 seconds to connect to the RPC server until it succeeds or the app is stopped
44-
for {
52+
func startWebsocket(h *healthcheck.Healthcheck) error {
4553
err := h.OpenWebsocket()
4654
if err != nil {
47-
log.Println(err.Error())
48-
time.Sleep(5 * time.Second)
49-
continue
55+
return err
5056
}
51-
break
52-
}
57+
return nil
5358
}

0 commit comments

Comments
 (0)