Skip to content

Commit 579a791

Browse files
authored
feat(dot/telemetry): Added connection retry (#1904)
1 parent a719a60 commit 579a791

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

dot/telemetry/telemetry.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ type Handler struct {
4343
connections []*telemetryConnection
4444
log log.Logger
4545
sendMessageTimeout time.Duration
46+
maxRetries int
47+
retryDelay time.Duration
4648
}
4749

4850
// Instance interface that telemetry handler instance needs to implement
@@ -61,7 +63,11 @@ var (
6163
initilised sync.Once
6264
)
6365

64-
const defaultMessageTimeout = time.Second
66+
const (
67+
defaultMessageTimeout = time.Second
68+
defaultMaxRetries = 5
69+
defaultRetryDelay = time.Second * 15
70+
)
6571

6672
// GetInstance singleton pattern to for accessing TelemetryHandler
6773
func GetInstance() Instance {
@@ -72,6 +78,8 @@ func GetInstance() Instance {
7278
msg: make(chan Message, 256),
7379
log: log.New("pkg", "telemetry"),
7480
sendMessageTimeout: defaultMessageTimeout,
81+
maxRetries: defaultMaxRetries,
82+
retryDelay: defaultRetryDelay,
7583
}
7684
go handlerInstance.startListening()
7785
})
@@ -94,17 +102,19 @@ func (h *Handler) Initialise(e bool) {
94102
// AddConnections adds the given telemetry endpoint as listeners that will receive telemetry data
95103
func (h *Handler) AddConnections(conns []*genesis.TelemetryEndpoint) {
96104
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
106117
}
107-
h.connections = append(h.connections, tConn)
108118
}
109119
}
110120

0 commit comments

Comments
 (0)