VOL-4207:
Fix data race that may possibly causing regression during subscriber
unprovision tests in the nightlies.
Change-Id: Ife13748777aafca545d381cd3aab096893e97a7a
diff --git a/internal/pkg/onuadaptercore/omci_vlan_config.go b/internal/pkg/onuadaptercore/omci_vlan_config.go
index 4f8247a..258731e 100644
--- a/internal/pkg/onuadaptercore/omci_vlan_config.go
+++ b/internal/pkg/onuadaptercore/omci_vlan_config.go
@@ -2570,10 +2570,12 @@
"ReceivedFrameVlanTaggingOperationTable": sliceEvtocdRule,
},
}
+ oFsm.mutexPLastTxMeInstance.Lock()
meInstance, err := oFsm.pOmciCC.sendSetEvtocdVar(context.TODO(),
oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true,
oFsm.pAdaptFsm.commChan, meParams)
if err != nil {
+ oFsm.mutexPLastTxMeInstance.Unlock()
logger.Errorw(ctx, "SetEvtocdVar set failed, aborting UniVlanConfigFsm!",
log.Fields{"device-id": oFsm.deviceID})
_ = oFsm.pAdaptFsm.pFsm.Event(vlanEvReset)
@@ -2582,6 +2584,7 @@
//accept also nil as (error) return value for writing to LastTx
// - this avoids misinterpretation of new received OMCI messages
oFsm.pLastTxMeInstance = meInstance
+ oFsm.mutexPLastTxMeInstance.Unlock()
//verify response
err = oFsm.waitforOmciResponse(ctx)
@@ -2997,13 +3000,16 @@
"MeterType": 1,
},
}
+ oFsm.mutexPLastTxMeInstance.Lock()
meInstance, errCreateTD := oFsm.pOmciCC.sendCreateTDVar(log.WithSpanFromContext(context.TODO(), ctx), oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout,
true, oFsm.pAdaptFsm.commChan, meParams)
if errCreateTD != nil {
+ oFsm.mutexPLastTxMeInstance.Unlock()
logger.Errorw(ctx, "Traffic Descriptor create failed", log.Fields{"device-id": oFsm.deviceID})
return err
}
oFsm.pLastTxMeInstance = meInstance
+ oFsm.mutexPLastTxMeInstance.Unlock()
err = oFsm.waitforOmciResponse(ctx)
if err != nil {
logger.Errorw(ctx, "Traffic Descriptor create failed, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID})
@@ -3028,13 +3034,16 @@
"TrafficManagementPointerForUpstream": gemPortID,
},
}
+ oFsm.mutexPLastTxMeInstance.Lock()
meInstance, err := oFsm.pOmciCC.sendSetGemNCTPVar(log.WithSpanFromContext(context.TODO(), ctx),
oFsm.pDeviceHandler.pOpenOnuAc.omciTimeout, true, oFsm.pAdaptFsm.commChan, meParams)
if err != nil {
+ oFsm.mutexPLastTxMeInstance.Unlock()
logger.Errorw(ctx, "GemNCTP set failed", log.Fields{"device-id": oFsm.deviceID})
return err
}
oFsm.pLastTxMeInstance = meInstance
+ oFsm.mutexPLastTxMeInstance.Unlock()
err = oFsm.waitforOmciResponse(ctx)
if err != nil {
logger.Errorw(ctx, "Upstream Traffic Descriptor set failed, aborting VlanConfig FSM!", log.Fields{"device-id": oFsm.deviceID})
diff --git a/internal/pkg/onuadaptercore/onu_metrics_manager.go b/internal/pkg/onuadaptercore/onu_metrics_manager.go
index ed1e869..b33c5a9 100644
--- a/internal/pkg/onuadaptercore/onu_metrics_manager.go
+++ b/internal/pkg/onuadaptercore/onu_metrics_manager.go
@@ -1589,7 +1589,9 @@
mm.onuMetricsManagerLock.Unlock()
}
}
+ mm.onuMetricsManagerLock.RLock()
logger.Debugw(ctx, "state create pm - done", log.Fields{"device-id": mm.pDeviceHandler.deviceID, "active-l2-pms": mm.activeL2Pms, "pms-to-add": mm.l2PmToAdd})
+ mm.onuMetricsManagerLock.RUnlock()
// Does not matter we send success or failure here.
// Those PMs that we failed to create will be attempted to create again in the next PM creation cycle (assuming
// we have not exceed max attempts to create the PM ME)
@@ -1609,7 +1611,7 @@
_ = copy(copyOfL2PmToDelete, mm.l2PmToDelete)
mm.onuMetricsManagerLock.RUnlock()
- logger.Debugw(ctx, "state delete pm", log.Fields{"device-id": mm.pDeviceHandler.deviceID, "pms-to-delete": mm.l2PmToDelete})
+ logger.Debugw(ctx, "state delete pm", log.Fields{"device-id": mm.pDeviceHandler.deviceID, "pms-to-delete": copyOfL2PmToDelete})
for _, n := range copyOfL2PmToDelete {
resp := false
cnt := 0
@@ -1775,7 +1777,9 @@
mm.onuMetricsManagerLock.Unlock()
}
}
+ mm.onuMetricsManagerLock.RLock()
logger.Debugw(ctx, "state delete pm - done", log.Fields{"device-id": mm.pDeviceHandler.deviceID, "active-l2-pms": mm.activeL2Pms, "pms-to-delete": mm.l2PmToDelete})
+ mm.onuMetricsManagerLock.RUnlock()
// Does not matter we send success or failure here.
// Those PMs that we failed to delete will be attempted to create again in the next PM collection cycle
go func() {