Fix another state-keeping thinko 80/101380/6
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 31 May 2022 18:54:42 +0000 (20:54 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 31 May 2022 20:54:12 +0000 (22:54 +0200)
We need to update pending before we add a listener, as the future
may have already completed and thus we could observe pending being
either null or point to the bad value.

Also update the corresponding checkState() to use identity comparison
and include a proper message.

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

index 9ff1137446bdd74dc7798d22fa956ed182321676..d7722fe3bcad1f0a2c921ed97b41cb01e9e0d62a 100644 (file)
@@ -7,7 +7,6 @@
  */
 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;
 
@@ -53,9 +52,9 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
                 address = new InetSocketAddress(address.getHostName(), address.getPort());
             }
             final ChannelFuture connectFuture = bootstrap.connect(address);
+            pending = connectFuture;
             // Add listener that attempts reconnect by invoking this method again.
             connectFuture.addListener((ChannelFutureListener) this::channelConnectComplete);
-            pending = connectFuture;
         } catch (final Exception e) {
             LOG.info("Failed to connect to {}", address, e);
             setFailure(e);
@@ -82,7 +81,7 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
     // Triggered when a connection attempt is resolved.
     private synchronized void channelConnectComplete(final ChannelFuture cf) {
         LOG.debug("Promise {} connection resolved", this);
-        checkState(pending.equals(cf));
+        verify(pending == cf, "Completed channel future %s while pending %s", cf, pending);
 
         /*
          * The promise we gave out could have been cancelled,