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

Change-Id: I05fd0bafee690803ba7ba1c91ce72559d720380c
diff --git a/VERSION b/VERSION
index eca07e4..ba053dd 100755
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.1.2
+2.1.3-dev264
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)