Skip to content

Commit ce4808f

Browse files
committed
Retry reconnects on EVM event subscriber for up to 30 seconds
1 parent 9e20910 commit ce4808f

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

services/ingestion/event_subscriber.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,30 @@ func (r *RPCEventSubscriber) subscribe(ctx context.Context, height uint64) <-cha
232232
return
233233
}
234234

235-
if err := connect(lastReceivedHeight); err != nil {
236-
eventsChan <- models.NewBlockEventsError(
237-
fmt.Errorf(
238-
"failed to resubscribe for events on height: %d, with: %w",
239-
lastReceivedHeight,
240-
err,
241-
),
242-
)
243-
return
235+
start := time.Now()
236+
attempts := 0
237+
pauseDuration, maxDuration := 200*time.Millisecond, 30*time.Second
238+
// Allow reconnect retries for up to 30 seconds, with retry
239+
// attempts every 200 ms.
240+
for {
241+
err := connect(lastReceivedHeight)
242+
if err == nil {
243+
break
244+
}
245+
246+
attempts++
247+
duration := time.Since(start)
248+
if duration >= maxDuration {
249+
eventsChan <- models.NewBlockEventsError(
250+
fmt.Errorf(
251+
"failed to resubscribe for events on height: %d, with: %w",
252+
lastReceivedHeight,
253+
err,
254+
),
255+
)
256+
return
257+
}
258+
time.Sleep(pauseDuration)
244259
}
245260
}
246261
}

0 commit comments

Comments
 (0)