BUG 9072 - Fix OVSDB TransactionChain memory leak 62/62462/2
authorVictor Pickard <vpickard@redhat.com>
Wed, 30 Aug 2017 18:52:19 +0000 (14:52 -0400)
committerAnil Vishnoi <vishnoianil@gmail.com>
Sat, 2 Sep 2017 00:48:28 +0000 (00:48 +0000)
TransactionChain is never closed. Add code to
close txChain when SouthboundProvider is closed.

This fix is part of memory leak cleanup efforts
for bug 9060 and bug 9034.

Change-Id: Ic24ec8081b02a35b73a4c640e751b75ee80bd143
Signed-off-by: Victor Pickard <vpickard@redhat.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvoker.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionInvokerImpl.java
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/SouthboundProviderTest.java

index e2b30876151eaed40d885c1f1844c9852032e903..b5ae74689073f76c7df9d2cb6536d76e337475c8 100644 (file)
@@ -106,6 +106,11 @@ public class SouthboundProvider implements AutoCloseable {
     @Override
     public void close() {
         LOG.info("SouthboundProvider Closed");
+        try {
+            txInvoker.close();
+        } catch (InterruptedException e) {
+            LOG.debug("SouthboundProvider failed to close TransactionInvoker.");
+        }
         cm.close();
         ovsdbDataTreeChangeListener.close();
         registration.close();
index 75a46e1b6ac070076d8db89314c85bca400d3c39..bb815356d0316ccb73be8912950d8aed98f056eb 100644 (file)
@@ -174,7 +174,8 @@ public class TransactionInvokerImpl implements TransactionInvoker,TransactionCha
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() throws InterruptedException {
+        this.chain.close();
         this.executor.shutdown();
         if (!this.executor.awaitTermination(1, TimeUnit.SECONDS)) {
             runTask.set(false);
index 8990f54a0b1883199493e4e56038d977c63ae2c6..e89a7b886fa5838cd790c894490f8cd178522f7e 100644 (file)
@@ -80,6 +80,34 @@ public class SouthboundProviderTest extends AbstractDataBrokerTest {
         }
     }
 
+    @Test
+    public void testInitWithClose() throws CandidateAlreadyRegisteredException {
+        // Indicate that this is the owner
+        when(entityOwnershipService.getOwnershipState(any(Entity.class))).thenReturn(
+                Optional.of(new EntityOwnershipState(true, true)));
+
+        try (SouthboundProvider southboundProvider = new SouthboundProvider(
+                getDataBroker(),
+                entityOwnershipService,
+                Mockito.mock(OvsdbConnection.class),
+                Mockito.mock(SchemaService.class),
+                Mockito.mock(BindingNormalizedNodeSerializer.class))) {
+
+            // Initiate the session
+            southboundProvider.init();
+
+            // Verify that at least one listener was registered
+            verify(entityOwnershipService, atLeastOnce()).registerListener(
+                    anyString(), any(EntityOwnershipListener.class));
+
+            // Verify that a candidate was registered
+            verify(entityOwnershipService).registerCandidate(any(Entity.class));
+
+            //Close the session
+            southboundProvider.close();
+        }
+    }
+
     @Test
     public void testGetDb() {
         when(entityOwnershipService.getOwnershipState(any(Entity.class))).thenReturn(