Merge "Bug 7846: ensure switch reconnection succeed in case of connection errors...
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / rpc / RpcManagerImpl.java
index 39eb472ca7d485ebbbcbcc52bc6b2f91246ffaf8..9d51e9d7755acf543e828b154ccabdc75e4ff14b 100644 (file)
@@ -76,6 +76,13 @@ public class RpcManagerImpl implements RpcManager {
                 convertorExecutor,
                 notificationPublishService);
 
+        // Clean up any old context present
+        RpcContext staleContext = contexts.remove(deviceInfo);
+        if (staleContext != null){
+            LOG.warn("Previous rpc context for node {} was not closed, closing the context.", deviceInfo);
+            staleContext.close();
+        }
+
         Verify.verify(contexts.putIfAbsent(deviceInfo, rpcContext) == null, "RpcCtx still not closed for node {}", deviceInfo.getNodeId());
         lifecycleService.setRpcContext(rpcContext);
         lifecycleService.registerDeviceRemovedHandler(this);