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>
*/
package org.opendaylight.netconf.nettyutil;
*/
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 static com.google.common.base.Verify.verify;
import static java.util.Objects.requireNonNull;
address = new InetSocketAddress(address.getHostName(), address.getPort());
}
final ChannelFuture connectFuture = bootstrap.connect(address);
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);
// 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);
} catch (final Exception e) {
LOG.info("Failed to connect to {}", address, e);
setFailure(e);
// Triggered when a connection attempt is resolved.
private synchronized void channelConnectComplete(final ChannelFuture cf) {
LOG.debug("Promise {} connection resolved", this);
// 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,
/*
* The promise we gave out could have been cancelled,