[VOL-4699] Fix panic in PM module in openonu-go adapter during Device Delete in Memory leak tests
Change-Id: I1baaa044ff311048d9ee3f6a5e368cdafe7220bc
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index fbf2ea7..6465a0c 100755
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -4548,6 +4548,12 @@
}
if dh.pOnuMetricsMgr != nil {
dh.pOnuMetricsMgr.PrepareForGarbageCollection(ctx, aDeviceID)
+ select {
+ case <-dh.pOnuMetricsMgr.GarbageCollectionComplete:
+ logger.Debugw(ctx, "pm fsm shut down and garbage collection complete", log.Fields{"deviceID": aDeviceID})
+ case <-time.After(pmmgr.MaxTimeForPmFsmShutDown * time.Second):
+ logger.Errorw(ctx, "fsm did not shut down in time", log.Fields{"deviceID": aDeviceID})
+ }
}
if dh.pAlarmMgr != nil {
dh.pAlarmMgr.PrepareForGarbageCollection(ctx, aDeviceID)
diff --git a/internal/pkg/core/openonu.go b/internal/pkg/core/openonu.go
index 60d2f81..0069794 100755
--- a/internal/pkg/core/openonu.go
+++ b/internal/pkg/core/openonu.go
@@ -331,6 +331,9 @@
handler.deletionInProgress = true
handler.mutexDeletionInProgressFlag.Unlock()
+ // Setting the device deletion progress flag will cause the PM FSM to cleanup for GC after FSM moves to NULL state
+ handler.pOnuMetricsMgr.SetdeviceDeletionInProgress(true)
+
if err := handler.resetFsms(ctx, true); err != nil {
errorsList = append(errorsList, err)
}