VOL-3023 - enable stop indication while in backoff

had to turn off "cyclomatic complexity" check on
readIndications function as it got too many branches.
not happy about that and it probably could use some
additional work.

Change-Id: I96a49b4cbb52cd1d997ece6d3472e340ec92788c
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index 7f8165e..212e096 100644
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -319,6 +319,7 @@
 	return nil
 }
 
+// nolint: gocyclo
 // readIndications to read the indications from the OLT device
 func (dh *DeviceHandler) readIndications(ctx context.Context) error {
 	defer logger.Debugw("indications-ended", log.Fields{"device-id": dh.device.Id})
@@ -372,7 +373,20 @@
 							"device-id": dh.device.Id})
 					indicationBackoff.Reset()
 				}
-				time.Sleep(indicationBackoff.NextBackOff())
+
+				// On failure process a backoff timer while watching for stopIndications
+				// events
+				backoff := time.NewTimer(indicationBackoff.NextBackOff())
+				select {
+				case <-dh.stopIndications:
+					logger.Debugw("stopping-collecting-indications-for-olt", log.Fields{"deviceID:": dh.device.Id})
+					if !backoff.Stop() {
+						<-backoff.C
+					}
+					break Loop
+				case <-backoff.C:
+					// backoff expired continue
+				}
 				if indications, err = dh.startOpenOltIndicationStream(ctx); err != nil {
 					return err
 				}