Detect stale conns when ping times out 03/71203/5
authorJosh <jhershbe@redhat.com>
Mon, 23 Apr 2018 10:11:54 +0000 (13:11 +0300)
committerVishal Thapar <vthapar@redhat.com>
Wed, 23 May 2018 04:42:34 +0000 (04:42 +0000)
When an ovsdb client connects StalePassiveConnectionService
checks to see if there are any previous connections to that
same client. If there are, they are pinged to determine
whether or not they are still actually connected. The
callback that handles the ping results does not fire
properly in the event of a timeout and the onFailure method
does not call
OvsdbConnectionService.notifyListenerForPassiveConnection
for the new connection. This results in the new connection
not being being reported "up the stack."

Note: easiest way to reproduce this is to "unplug" (destroy
in libvirt) a VM running the OVS and then start it.

Issue: NETVIRT-1178
Change-Id: Ie3494c46719954f862d8edb6e8921a752dcd30ea
Signed-off-by: Josh <jhershbe@redhat.com>
library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/StalePassiveConnectionService.java

index a74fa1be97544849bbb697da8bb1e9dc7df6894a..66f0f3e148f105b4f61b14286aed1f5e0080adc9 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.util.concurrent.SettableFuture;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.concurrent.CancellationException;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledExecutorService;
@@ -136,7 +137,24 @@ public class StalePassiveConnectionService implements AutoCloseable {
 
             @Override
             public void onFailure(Throwable throwable) {
-                LOG.error("Error in checking stale connections)", throwable);
+                if (!(throwable instanceof CancellationException)) {
+                    LOG.error("Error in checking stale connections)", throwable);
+                    return;
+                }
+
+                LOG.debug("Ping for {} was cancelled as a result of timeout. Assuming client connection is gone.",
+                                        cbForClient);
+
+                if (cbForClient.isActive()) {
+                    cbForClient.disconnect();
+                }
+
+                clientFutureMap.remove(cbForClient);
+
+                if (clientFutureMap.isEmpty()) {
+                    OvsdbConnectionService.notifyListenerForPassiveConnection(newClient);
+                    pendingConnectionClients.remove(newClient);
+                }
             }
         };
     }