Fix session shutdown race 15/105115/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 31 Mar 2023 11:05:26 +0000 (13:05 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 31 Mar 2023 11:07:31 +0000 (13:07 +0200)
We must not shut down the underlying transaction chain before we have
cleared all possible interactions with it.

JIRA: BGPCEP-1020
Change-Id: Iad2836827eb0b7781152cc5d8dc1997547482596
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit a5a311b52cdf5cbe9bce5f0dff057cb3e7e71ea6)

pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/AbstractTopologySessionListener.java
pcep/topology/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/SessionStateUpdater.java

index 7678e405ce691274e433f52224739b7799778045..cdce51e91b0a6e97c7c92fb6df7b2ee5f98b9d52 100644 (file)
@@ -272,16 +272,19 @@ public abstract class AbstractTopologySessionListener implements TopologySession
     }
 
     /**
-     * Tear down the given PCEP session. It's OK to call this method even after the session
-     * is already down. It always clear up the current session status.
+     * Tear down the given PCEP session. It's OK to call this method even after the session is already down. It always
+     * clears up the current session status.
      */
     @SuppressWarnings("checkstyle:IllegalCatch")
     private void tearDown(final PCEPSession psession) {
         requireNonNull(psession);
         synchronized (serverSessionManager) {
             synchronized (this) {
-                serverSessionManager.releaseNodeState(nodeState, psession.getRemoteAddress(), isLspDbPersisted());
+                // Lifecycle madness: we need to shut down the listener through clearNodeState() and only then release
+                // nodeState, as that ends up shutting down the underlying transaction chain.
+                final var tmp = nodeState;
                 clearNodeState();
+                serverSessionManager.releaseNodeState(tmp, psession.getRemoteAddress(), isLspDbPersisted());
 
                 try {
                     if (session != null) {
index e39e9766b8f6b08941cf13d2076d9ff4fbf4c4f6..6b7a1160a6ce9f2f7a312a97d0ec65419fc445e7 100644 (file)
@@ -113,7 +113,6 @@ final class SessionStateUpdater {
         return tx.commit();
     }
 
-    // FIXME: add a caller
     @NonNull FluentFuture<? extends @NonNull CommitInfo> removeStatistics() {
         final var tx = node.getChain().newWriteOnlyTransaction();
         tx.delete(LogicalDatastoreType.OPERATIONAL, node.getNodeId().augmentation(PcepTopologyNodeStatsAug.class));