[VOL-4525] openonuAdapterGo - reconciling of ONU falls back from status success to falied

Change-Id: I177bcdcb75990d6cc0860dcce114ac0a39d2eee7
diff --git a/VERSION b/VERSION
index 14d63ad..76f938b 100755
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.1.2-dev260
+2.1.2-dev261
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index a26246c..3cbd160 100755
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -1053,14 +1053,14 @@
 				log.Fields{"device-id": dh.DeviceID})
 			dh.stopReconciling(ctx, true, cWaitReconcileFlowAbortOnSuccess)
 			if pDevEntry != nil {
-				pDevEntry.SendChReconcilingFlowsFinished(true)
+				pDevEntry.SendChReconcilingFlowsFinished(ctx, true)
 			}
 		} else {
 			logger.Errorw(ctx, "reconciling - timeout waiting for reconciling flows for all UNI's to be finished!",
 				log.Fields{"device-id": dh.DeviceID})
 			dh.stopReconciling(ctx, false, cWaitReconcileFlowAbortOnError)
 			if pDevEntry != nil {
-				pDevEntry.SendChReconcilingFlowsFinished(false)
+				pDevEntry.SendChReconcilingFlowsFinished(ctx, false)
 			}
 			return
 		}
diff --git a/internal/pkg/mib/mib_sync.go b/internal/pkg/mib/mib_sync.go
index 8da6244..03937c4 100755
--- a/internal/pkg/mib/mib_sync.go
+++ b/internal/pkg/mib/mib_sync.go
@@ -401,12 +401,14 @@
 		if oo.baseDeviceHandler.ReconcileDeviceTechProf(ctx) {
 			// start go routine with select() on reconciling flow channel before
 			// starting flow reconciling process to prevent loss of any signal
-			go func() {
+			syncChannel := make(chan struct{})
+			go func(aSyncChannel chan struct{}) {
 				// In multi-ONU/multi-flow environment stopping reconcilement has to be delayed until
 				// we get a signal that the processing of the last step to rebuild the adapter internal
 				// flow data is finished.
 				expiry := oo.baseDeviceHandler.GetReconcileExpiryVlanConfigAbort()
 				oo.setReconcilingFlows(true)
+				aSyncChannel <- struct{}{}
 				select {
 				case success := <-oo.chReconcilingFlowsFinished:
 					if success {
@@ -424,7 +426,10 @@
 					_ = oo.PMibUploadFsm.PFsm.Event(UlEvMismatch)
 				}
 				oo.setReconcilingFlows(false)
-			}()
+			}(syncChannel)
+			// block further processing until the above Go routine has really started
+			// and is ready to receive values from chReconcilingFlowsFinished
+			<-syncChannel
 			oo.baseDeviceHandler.ReconcileDeviceFlowConfig(ctx)
 		}
 	} else {
@@ -1197,7 +1202,7 @@
 func (oo *OnuDeviceEntry) CancelProcessing(ctx context.Context) {
 
 	if oo.isReconcilingFlows() {
-		oo.SendChReconcilingFlowsFinished(false)
+		oo.SendChReconcilingFlowsFinished(ctx, false)
 	}
 	//the MibSync FSM might be active all the ONU-active time,
 	// hence it must be stopped unconditionally
diff --git a/internal/pkg/mib/onu_device_entry.go b/internal/pkg/mib/onu_device_entry.go
index 8ebf084..e956622 100755
--- a/internal/pkg/mib/onu_device_entry.go
+++ b/internal/pkg/mib/onu_device_entry.go
@@ -987,12 +987,14 @@
 }
 
 // SendChReconcilingFlowsFinished - TODO: add comment
-func (oo *OnuDeviceEntry) SendChReconcilingFlowsFinished(value bool) {
+func (oo *OnuDeviceEntry) SendChReconcilingFlowsFinished(ctx context.Context, value bool) {
 	if oo != nil { //if the object still exists (might have been already deleted in background)
 		//use asynchronous channel sending to avoid stucking on non-waiting receiver
 		select {
 		case oo.chReconcilingFlowsFinished <- value:
+			logger.Debugw(ctx, "reconciling - flows finished sent", log.Fields{"device-id": oo.deviceID})
 		default:
+			logger.Infow(ctx, "reconciling - flows finished not sent!", log.Fields{"device-id": oo.deviceID})
 		}
 	}
 }