From 29e06cbd92b039d501a004cabcf0eb19f63c427a Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 31 May 2022 21:04:53 +0200 Subject: [PATCH] Reduce exception guard We really should not be catching Exceptions here and once connect() returns we should be completely asynchronous. Reduce the amount of code protected by the try/catch block. Change-Id: I673cc4f0a52cefd2659a5db5a96417e00fd89422 Signed-off-by: Robert Varga --- .../netconf/nettyutil/NetconfSessionPromise.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 178be8bfe1..4a8fb7f88c 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 @@ -54,18 +54,21 @@ final class NetconfSessionPromise extends DefaultPromi LOG.debug("Promise {} attempting connect for {}ms", this, timeout); + final ChannelFuture connectFuture; try { if (address.isUnresolved()) { 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); + connectFuture = bootstrap.connect(address); } catch (final Exception e) { LOG.info("Failed to connect to {}", address, e); setFailure(e); + return; } + + pending = connectFuture; + // Add listener that attempts reconnect by invoking this method again. + connectFuture.addListener((ChannelFutureListener) this::channelConnectComplete); } @Override -- 2.36.6