@@ -20,15 +20,27 @@ var serveCmd = &cobra.Command{
20
20
log .Fatalf ("Error parsing log level: %s\n " , err .Error ())
21
21
}
22
22
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
26
42
}
27
43
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
-
32
44
log .Fatalln (h .StartServer ())
33
45
},
34
46
}
@@ -37,17 +49,10 @@ func init() {
37
49
rootCmd .AddCommand (serveCmd )
38
50
}
39
51
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 {
45
53
err := h .OpenWebsocket ()
46
54
if err != nil {
47
- log .Println (err .Error ())
48
- time .Sleep (5 * time .Second )
49
- continue
55
+ return err
50
56
}
51
- break
52
- }
57
+ return nil
53
58
}
0 commit comments