[VOL-4102] Adding exponential backoff to retry reconnection in case of a
gRPC connection drop to the device
Adding device-id to flow logs
Change-Id: Ia279743af6d052c5c9f1a5a62c3b183c82aab175
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index 9915268..e81cd8f 100644
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -430,9 +430,26 @@
log.Fields{"err": err,
"device-id": dh.device.Id})
}
- if indications, err = dh.startOpenOltIndicationStream(ctx); err != nil {
+ // if the connection drops we should retry to establish a new one for a little bit
+ // for now set to 2 Minutes
+ reconnectBackoff := backoff.NewExponentialBackOff()
+ reconnectBackoff.MaxElapsedTime = dh.openOLT.ReconnectTimeout
+ reconnectOperation := func() error {
+ logger.Debugw(ctx, "attempting-reconnection-to-device",
+ log.Fields{"err": err,
+ "device-id": dh.device.Id})
+ if indications, err = dh.startOpenOltIndicationStream(ctx); err != nil {
+ return err
+ }
+ return nil
+ }
+ if err = backoff.Retry(reconnectOperation, reconnectBackoff); err != nil {
+ logger.Errorw(ctx, "cannot-reconnect-to-device-backoff-expired",
+ log.Fields{"err": err,
+ "device-id": dh.device.Id})
return err
}
+
// once we re-initialized the indication stream, continue to read indications
continue
}