fix to avoid flooding of reconcile rpc request

Change-Id: Ic25858cb36106d08d06de06d0d98bf8be150a970
diff --git a/rw_core/core/device/agent.go b/rw_core/core/device/agent.go
index 7cd96d8..faf3845 100755
--- a/rw_core/core/device/agent.go
+++ b/rw_core/core/device/agent.go
@@ -1304,7 +1304,6 @@
 		return
 	}
 
-	logger.Debugw(ctx, "retrying-reconciling", log.Fields{"deviceID": device.Id})
 	reconcilingBackoff := backoff.NewExponentialBackOff()
 	reconcilingBackoff.InitialInterval = agent.config.BackoffRetryInitialInterval
 	reconcilingBackoff.MaxElapsedTime = agent.config.BackoffRetryMaxElapsedTime
@@ -1315,7 +1314,6 @@
 	agent.stopReconciling = make(chan int)
 	agent.stopReconcilingMutex.Unlock()
 
-Loop:
 	for {
 		// Use an exponential back off to prevent getting into a tight loop
 		duration := reconcilingBackoff.NextBackOff()
@@ -1332,6 +1330,7 @@
 
 		backoffTimer := time.NewTimer(duration)
 
+		logger.Debugw(ctx, "retrying-reconciling", log.Fields{"deviceID": device.Id})
 		// Send a reconcile request to the adapter.
 		ch, err := agent.adapterProxy.ReconcileDevice(ctx, agent.device)
 		//release lock before moving further
@@ -1355,10 +1354,14 @@
 			desc = err.Error()
 			logger.Errorf(ctx, desc)
 			agent.logDeviceUpdate(ctx, "Reconciling", nil, nil, operStatus, &desc)
+			<-backoffTimer.C
 		} else {
 			operStatus = &common.OperationResp{Code: common.OperationResp_OPERATION_IN_PROGRESS}
 			agent.logDeviceUpdate(ctx, "Reconciling", nil, nil, operStatus, &desc)
-			break Loop
+			if !backoffTimer.Stop() {
+				<-backoffTimer.C
+			}
+			return
 		}
 
 		// Take lock back before retrying
@@ -1379,7 +1382,7 @@
 			return errors.New("channel on which reconcile response is awaited is closed")
 		} else if resp.Err != nil {
 			//error encountered
-			return errors.New("error encountered while retrying reconcile")
+			return fmt.Errorf("error encountered while retrying reconcile. Err: %s", resp.Err.Error())
 		}
 
 		//In case of success quit retrying and wait for adapter to reset operation state of device