[VOL-5424] - fix reconcile cleanup when reconcile stops

Change-Id: I20dfccf7c327a10b316cbe18c9aa5ac7946d8763
Signed-off-by: Sridhar Ravindra <sridhar.ravindra@radisys.com>
diff --git a/VERSION b/VERSION
index 4f2c1d1..d738d02 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.6.6
+3.6.6-dev1
diff --git a/rw_core/core/device/agent.go b/rw_core/core/device/agent.go
index 22ec799..92a7e1c 100755
--- a/rw_core/core/device/agent.go
+++ b/rw_core/core/device/agent.go
@@ -1527,12 +1527,6 @@
 	// up when the loop breaks
 	var backoffTimer *time.Timer
 	isDeviceReconciledErr := false
-	defer func() {
-		err := agent.reconcilingCleanup(ctx)
-		if err != nil {
-			logger.Errorf(ctx, "Error during reconcile cleanup", err.Error())
-		}
-	}()
 
 retry:
 	for {
@@ -1557,6 +1551,10 @@
 					"device-id": device.Id})
 				// Release lock before reconcile clean up
 				agent.requestQueue.RequestComplete()
+				err := agent.reconcilingCleanup(ctx)
+				if err != nil {
+					logger.Errorf(ctx, "Error during reconcile cleanup", err.Error())
+				}
 				break retry
 			}
 			// If we reach a maximum then warn and reset the backoff