From e91db4667655b53da8a782449d577d72d8d43ef7 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 26 Jan 2022 10:09:21 +0100 Subject: [PATCH] Do not reuse inactive handler We have a simple event dispatch handler here, which is stateless and can be reused, except Netty's defences are rejecting such reuse. Since it is a very simple object, just do not bother with its reuse. JIRA: NETCONF-852 Change-Id: I40b48b0a8e14a0a271043bb9fb4b471cfd56a8e7 Signed-off-by: Robert Varga (cherry picked from commit 438ed86b4a3e80cd18f52b40e6faf4260e14d6ac) --- .../netconf/nettyutil/ReconnectPromise.java | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java index b4799811a9..00345e17c9 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java @@ -9,6 +9,7 @@ package org.opendaylight.netconf.nettyutil; import static java.util.Objects.requireNonNull; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -37,30 +38,6 @@ final class ReconnectPromise initializer; private final Promise firstSessionFuture; - /** - * Channel handler that responds to channelInactive event and reconnects the session unless the promise is - * cancelled. - */ - private final ChannelInboundHandlerAdapter inboundHandler = new ChannelInboundHandlerAdapter() { - @Override - public void channelInactive(final ChannelHandlerContext ctx) { - // This is the ultimate channel inactive handler, not forwarding - if (isCancelled()) { - return; - } - - synchronized (ReconnectPromise.this) { - final Future attempt = pending; - if (!attempt.isDone() || !attempt.isSuccess()) { - // Connection refused, negotiation failed, or similar - LOG.debug("Connection to {} was dropped during negotiation, reattempting", address); - } - - LOG.debug("Reconnecting after connection to {} was dropped", address); - lockedConnect(); - } - } - }; @GuardedBy("this") private Future pending; @@ -111,7 +88,12 @@ final class ReconnectPromise attempt = pending; + if (!attempt.isDone() || !attempt.isSuccess()) { + // Connection refused, negotiation failed, or similar + LOG.debug("Connection to {} was dropped during negotiation, reattempting", address); + } + + LOG.debug("Reconnecting after connection to {} was dropped", address); + lockedConnect(); + } + } } -- 2.36.6