Fix potential transaction leak 50/116450/5
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 5 May 2025 23:15:44 +0000 (01:15 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Tue, 6 May 2025 11:11:57 +0000 (11:11 +0000)
We allocate the transaction too early and if we end up throwing an
exception we end up not aboring it, leading to a leak.

Move allocation to where we need it, making it clear we not lose track
of it.

JIRA: NETCONF-1449
Change-Id: I3f282cb09ab03251c81e36547a27ba60316efc4f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
plugins/restconf-server-mdsal/src/main/java/org/opendaylight/restconf/server/mdsal/MdsalRestconfStreamRegistry.java

index a097002b067481e2718ca3128ad6d48397573c50..1b75adfb1c73123421c1e1519d7707d0f85896bf 100644 (file)
@@ -282,7 +282,6 @@ public final class MdsalRestconfStreamRegistry extends AbstractRestconfStreamReg
     public ListenableFuture<Void> updateReceiver(final ReceiverHolder receiver, final long counter,
             final ReceiverHolder.RecordType recordType) {
         // Now issue a merge operation
-        final var tx = dataBroker.newWriteOnlyTransaction();
         final var subscriptionId = receiver.subscriptionId();
         final var sentEventIid = YangInstanceIdentifier.builder()
             .node(SUBSCRIPTIONS_NODEID)
@@ -308,6 +307,7 @@ public final class MdsalRestconfStreamRegistry extends AbstractRestconfStreamReg
             default -> throw new IllegalArgumentException("Unknown record type: " + recordType);
         }
 
+        final var tx = dataBroker.newWriteOnlyTransaction();
         tx.merge(LogicalDatastoreType.OPERATIONAL, sentEventIid.build(), counterValue);
         return tx.commit().transform(unused -> null, MoreExecutors.directExecutor());
     }