@@ -43,6 +43,8 @@ type Handler struct {
43
43
connections []* telemetryConnection
44
44
log log.Logger
45
45
sendMessageTimeout time.Duration
46
+ maxRetries int
47
+ retryDelay time.Duration
46
48
}
47
49
48
50
// Instance interface that telemetry handler instance needs to implement
61
63
initilised sync.Once
62
64
)
63
65
64
- const defaultMessageTimeout = time .Second
66
+ const (
67
+ defaultMessageTimeout = time .Second
68
+ defaultMaxRetries = 5
69
+ defaultRetryDelay = time .Second * 15
70
+ )
65
71
66
72
// GetInstance singleton pattern to for accessing TelemetryHandler
67
73
func GetInstance () Instance {
@@ -72,6 +78,8 @@ func GetInstance() Instance {
72
78
msg : make (chan Message , 256 ),
73
79
log : log .New ("pkg" , "telemetry" ),
74
80
sendMessageTimeout : defaultMessageTimeout ,
81
+ maxRetries : defaultMaxRetries ,
82
+ retryDelay : defaultRetryDelay ,
75
83
}
76
84
go handlerInstance .startListening ()
77
85
})
@@ -94,17 +102,19 @@ func (h *Handler) Initialise(e bool) {
94
102
// AddConnections adds the given telemetry endpoint as listeners that will receive telemetry data
95
103
func (h * Handler ) AddConnections (conns []* genesis.TelemetryEndpoint ) {
96
104
for _ , v := range conns {
97
- c , _ , err := websocket .DefaultDialer .Dial (v .Endpoint , nil )
98
- if err != nil {
99
- // TODO: try reconnecting if there is an error connecting (#1862)
100
- h .log .Debug ("issue adding telemetry connection" , "error" , err )
101
- continue
102
- }
103
- tConn := & telemetryConnection {
104
- wsconn : c ,
105
- verbosity : v .Verbosity ,
105
+ for connAttempts := 0 ; connAttempts < h .maxRetries ; connAttempts ++ {
106
+ c , _ , err := websocket .DefaultDialer .Dial (v .Endpoint , nil )
107
+ if err != nil {
108
+ h .log .Debug ("issue adding telemetry connection" , "error" , err )
109
+ time .Sleep (h .retryDelay )
110
+ continue
111
+ }
112
+ h .connections = append (h .connections , & telemetryConnection {
113
+ wsconn : c ,
114
+ verbosity : v .Verbosity ,
115
+ })
116
+ break
106
117
}
107
- h .connections = append (h .connections , tConn )
108
118
}
109
119
}
110
120
0 commit comments