[VOL-3889] missing device reason update from flow removal after ONU reboot

Signed-off-by: mpagenko <michael.pagenkopf@adtran.com>
Change-Id: I1e3eb63e044901c814f453b99388db56ae171d00
diff --git a/internal/pkg/onuadaptercore/device_handler.go b/internal/pkg/onuadaptercore/device_handler.go
index 59cd8d0..b720f4f 100644
--- a/internal/pkg/onuadaptercore/device_handler.go
+++ b/internal/pkg/onuadaptercore/device_handler.go
@@ -1669,23 +1669,20 @@
 		// FSM  stop maybe encapsulated as OnuTP method - perhaps later in context of module splitting
 		if dh.pOnuTP.pAniConfigFsm != nil {
 			for uniTP := range dh.pOnuTP.pAniConfigFsm {
-				_ = dh.pOnuTP.pAniConfigFsm[uniTP].pAdaptFsm.pFsm.Event(aniEvReset)
+				dh.pOnuTP.pAniConfigFsm[uniTP].CancelProcessing()
 			}
 		}
 		for _, uniPort := range dh.uniEntityMap {
 			// reset the possibly existing VlanConfigFsm
 			dh.lockVlanConfig.RLock()
 			if pVlanFilterFsm, exist := dh.UniVlanConfigFsmMap[uniPort.uniID]; exist {
-				dh.lockVlanConfig.RUnlock()
 				//VlanFilterFsm exists and was already started
-				pVlanFilterStatemachine := pVlanFilterFsm.pAdaptFsm.pFsm
-				if pVlanFilterStatemachine != nil {
-					//reset of all Fsm is always accompanied by global persistency data removal
-					//  no need to remove specific data
-					pVlanFilterFsm.RequestClearPersistency(false)
-					//and reset the UniVlanConfig FSM
-					_ = pVlanFilterStatemachine.Event(vlanEvReset)
-				}
+				dh.lockVlanConfig.RUnlock()
+				//reset of all Fsm is always accompanied by global persistency data removal
+				//  no need to remove specific data
+				pVlanFilterFsm.RequestClearPersistency(false)
+				//ensure the FSM processing is stopped in case waiting for some response
+				pVlanFilterFsm.CancelProcessing()
 			} else {
 				dh.lockVlanConfig.RUnlock()
 			}
@@ -1708,6 +1705,7 @@
 	}
 	dh.lockUpgradeFsm.RUnlock()
 
+	logger.Infow(ctx, "resetFsms done", log.Fields{"device-id": dh.deviceID})
 	return nil
 }
 
@@ -2596,8 +2594,10 @@
 		dh.pOpenOnuAc.AcceptIncrementalEvto, aCookieSlice, aMatchVlan, aSetVlan, aSetPcp)
 	if pVlanFilterFsm != nil {
 		dh.lockVlanConfig.Lock()
+		//ensure the mutex is locked throughout the state transition to 'starting' to prevent unintended (ignored) events to be sent there
+		//  (from parallel processing)
+		defer dh.lockVlanConfig.Unlock()
 		dh.UniVlanConfigFsmMap[apUniPort.uniID] = pVlanFilterFsm
-		dh.lockVlanConfig.Unlock()
 		pVlanFilterStatemachine := pVlanFilterFsm.pAdaptFsm.pFsm
 		if pVlanFilterStatemachine != nil {
 			if pVlanFilterStatemachine.Is(vlanStDisabled) {