From: Robert Varga Date: Tue, 31 May 2022 18:54:42 +0000 (+0200) Subject: Fix another state-keeping thinko X-Git-Tag: v4.0.0~61 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=refs%2Fchanges%2F80%2F101380%2F6;p=netconf.git Fix another state-keeping thinko 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 --- diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java index 9ff1137446..d7722fe3bc 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java @@ -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 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 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,