[VOL-4533] openonuAdapterGo - sporadically uni ports are missing after reconcile test

Change-Id: Ib3a93c94077dee49db91e6c756dc28fa1c1932d5
diff --git a/.gitreview b/.gitreview
index 6e7dab7..84929cb 100644
--- a/.gitreview
+++ b/.gitreview
@@ -3,3 +3,4 @@
 port=29418
 project=voltha-openonu-adapter-go.git
 defaultremote=origin
+defaultbranch=voltha-2.9
\ No newline at end of file
diff --git a/VERSION b/VERSION
index eca07e4..ac2cdeb 100755
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.1.2
+2.1.3
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index 3cbd160..fb6d1ff 100755
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -3984,6 +3984,16 @@
 				log.Fields{"timeout": dh.reconcileExpiryComplete, "device-id": dh.DeviceID})
 			select {
 			case success := <-dh.chReconcilingFinished:
+				logger.Debugw(ctx, "reconciling finished signal received",
+					log.Fields{"device-id": dh.DeviceID, "dh.chReconcilingFinished": dh.chReconcilingFinished})
+				// To guarantee that the case-branch below is completely processed before reconciling processing is continued,
+				// dh.mutexReconcilingFlag is locked already here. Thereby it is ensured, that further reconciling processing is stopped
+				// at next call of dh.IsReconciling() until dh.reconciling is set after informing core about finished reconciling below.
+				// This change addresses a problem described in VOL-4533 where the flag dh.reconciling not yet reset causes the uni ports
+				// not to be created in ONOS in function dh.addUniPort(), when reconciling was started in reason "starting-openomci".
+				// TODO: Keeping the mutex beyond an RPC towards core seems justifiable, as the effects here are easily overseeable.
+				// However, a later refactoring of the functionality remains unaffected.
+				dh.mutexReconcilingFlag.Lock()
 				if success {
 					if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
 						logger.Errorw(ctx, "No valid OnuDevice - aborting Core DeviceStateUpdate",
@@ -4037,6 +4047,7 @@
 			case <-time.After(dh.reconcileExpiryComplete):
 				logger.Errorw(ctx, "timeout waiting for reconciling to be finished!",
 					log.Fields{"device-id": dh.DeviceID})
+				dh.mutexReconcilingFlag.Lock()
 
 				if onuDevEntry := dh.GetOnuDeviceEntry(ctx, true); onuDevEntry == nil {
 					logger.Errorw(ctx, "No valid OnuDevice",
@@ -4052,7 +4063,6 @@
 				dh.deviceReconcileFailedUpdate(ctx, cmn.DrReconcileMaxTimeout, connectStatus)
 
 			}
-			dh.mutexReconcilingFlag.Lock()
 			dh.reconciling = cNoReconciling
 			dh.mutexReconcilingFlag.Unlock()
 			dh.SetReconcilingReasonUpdate(false)