Fix state transition thinko 79/101379/7
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 31 May 2022 18:37:29 +0000 (20:37 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 31 May 2022 20:54:12 +0000 (22:54 +0200)
The future returned from reconnect strategy may have completed before
we add a listener. Make sure we record the future before adding the
listener.

Also change checkState() to a verify() with a proper identity check
to work with nulls and a proper message.

JIRA: NETCONF-827
Change-Id: Ica152cd1445e797c122e542aa1138232f11c6736
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java

index 6136452a3bf29233d22f238c145a7e43efa4ca10..9ff1137446bdd74dc7798d22fa956ed182321676 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netconf.nettyutil;
 
 import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.base.Verify.verify;
 import static java.util.Objects.requireNonNull;
 
 import io.netty.bootstrap.Bootstrap;
@@ -108,14 +109,14 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
         LOG.debug("Attempt to connect to {} failed", address, cf.cause());
 
         final Future<Void> rf = strategy.scheduleReconnect(cf.cause());
-        rf.addListener(this::reconnectFutureComplete);
         pending = rf;
+        rf.addListener(this::reconnectFutureComplete);
     }
 
     // Triggered when a connection attempt is to be made.
     private synchronized void reconnectFutureComplete(final Future<?> sf) {
         LOG.debug("Promise {} strategy triggered reconnect", this);
-        checkState(pending.equals(sf));
+        verify(pending == sf, "Completed strategy future %s while pending %s", sf, pending);
 
         /*
          * The promise we gave out could have been cancelled,