[VOL-4064] Close the previous TCP (GRPC) connection before we establish a new one.

Change-Id: I57055268bba187e28377ac32203092693f88346b
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index 96d67b7..9915268 100644
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -711,7 +711,17 @@
 // doStateInit dial the grpc before going to init state
 func (dh *DeviceHandler) doStateInit(ctx context.Context) error {
 	var err error
-	// Use Intercepters to automatically inject and publish Open Tracing Spans by this GRPC client
+
+	// if the connection is already available, close the previous connection (olt reboot case)
+	if dh.clientCon != nil {
+		if err = dh.clientCon.Close(); err != nil {
+			logger.Errorw(ctx, "failed-to-close-previous-connection", log.Fields{"device-id": dh.device.Id})
+		} else {
+			logger.Debugw(ctx, "previous-grpc-channel-closed-successfully", log.Fields{"device-id": dh.device.Id})
+		}
+	}
+
+	// Use Interceptors to automatically inject and publish Open Tracing Spans by this GRPC client
 	dh.clientCon, err = grpc.Dial(dh.device.GetHostAndPort(),
 		grpc.WithInsecure(),
 		grpc.WithBlock(),