[VOL-5531] Onu adapter crash fix in sending omci requests

Change-Id: I50d05f6ab192c040458678bf9ed290257fa9b874
Signed-off-by: balaji.nagarajan <balaji.nagarajan@radisys.com>
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index cbb9acd..bba3f4a 100755
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -5225,14 +5225,6 @@
 	// cleanup routines a chance to come to an end
 	time.Sleep(2 * time.Second)
 
-	if dh.pOnuOmciDevice != nil {
-		if dh.pOnuOmciDevice.PDevOmciCC != nil {
-			// Since we cannot rule out that one of the handlers had initiated any OMCI configurations during its
-			// reset handling (even in future coding), request monitoring is canceled here one last time to
-			// be sure that all corresponding go routines are terminated
-			dh.pOnuOmciDevice.PDevOmciCC.CancelRequestMonitoring(ctx)
-		}
-	}
 	time.Sleep(3 * time.Second)
 
 	if dh.pOnuTP != nil {
diff --git a/internal/pkg/core/openonu.go b/internal/pkg/core/openonu.go
index fbd7be1..fce08b4 100755
--- a/internal/pkg/core/openonu.go
+++ b/internal/pkg/core/openonu.go
@@ -366,6 +366,15 @@
 			handler.pOnuMetricsMgr.SetdeviceDeletionInProgress(true)
 		}
 
+		if handler.pOnuOmciDevice != nil {
+			if handler.pOnuOmciDevice.PDevOmciCC != nil {
+				// Since we cannot rule out that one of the handlers had initiated any OMCI configurations during its
+				// reset handling (even in future coding), request monitoring is canceled here one last time to
+				// be sure that all corresponding go routines are terminated
+				handler.pOnuOmciDevice.PDevOmciCC.CancelRequestMonitoring(ctx)
+			}
+		}
+
 		close(handler.deviceDeleteCommChan)
 		if resetErr := handler.resetFsms(ctx, true); resetErr != nil {
 			logger.Errorw(ctx, "failed to reset FSMs for the device", log.Fields{"device-id": device.Id, "err": resetErr})