[VOL-5565]:stop heartbeat routine before device cleanup

Change-Id: I3b2b8aa98374c46ef57b2320f6549f133a91085d
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 58bf3bd..ea6eedf 100755
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -3145,6 +3145,12 @@
 	if dh.isReadIndicationRoutineActive {
 		dh.stopIndications <- true
 	}
+
+	// stop the heartbeat check routine
+	if dh.isHeartbeatCheckActive {
+		dh.stopHeartbeatCheck <- true
+	}
+
 	dh.lockDevice.RUnlock()
 
 	if err = dh.updateDeviceStateInCore(ctx, &ca.DeviceStateFilter{
@@ -3174,10 +3180,7 @@
 	if dh.isCollectorActive {
 		dh.stopCollector <- true
 	}
-	// stop the heartbeat check routine
-	if dh.isHeartbeatCheckActive {
-		dh.stopHeartbeatCheck <- true
-	}
+
 	dh.lockDevice.RUnlock()
 
 	dh.StopAllFlowRoutines(ctx)