From: Robert Varga Date: Tue, 31 May 2022 18:37:29 +0000 (+0200) Subject: Fix state transition thinko X-Git-Tag: v4.0.0~62 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=netconf.git;a=commitdiff_plain;h=5e9f3517718f4475c3026acba0a5afb6f19388fa Fix state transition thinko 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 --- 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 6136452a3b..9ff1137446 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 @@ -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 extends DefaultPromi LOG.debug("Attempt to connect to {} failed", address, cf.cause()); final Future 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,