From 572b4c3e729ac024e07782e59e94775ebfedb306 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 2 Dec 2016 10:34:33 +0100 Subject: [PATCH] Port assert from 5.x to master I added an assertion to Netty4/Netty3Transport in 5.x that is not in master yet. This commit port the assert to ensure we consumed all connection in `connectToChannels` --- .../org/elasticsearch/transport/netty4/Netty4Transport.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java index 20dd2d1a9fc..e1e497a4161 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java @@ -345,7 +345,6 @@ public class Netty4Transport extends TcpTransport { final NodeChannels nodeChannels = new NodeChannels(channels, profile); boolean success = false; try { - final int numConnections = channels.length; final TimeValue connectTimeout; final Bootstrap bootstrap; final TimeValue defaultConnectTimeout = defaultConnectionProfile.getConnectTimeout(); @@ -357,9 +356,9 @@ public class Netty4Transport extends TcpTransport { connectTimeout = defaultConnectTimeout; bootstrap = this.bootstrap; } - final ArrayList connections = new ArrayList<>(numConnections); + final ArrayList connections = new ArrayList<>(channels.length); final InetSocketAddress address = node.getAddress().address(); - for (int i = 0; i < numConnections; i++) { + for (int i = 0; i < channels.length; i++) { connections.add(bootstrap.connect(address)); } final Iterator iterator = connections.iterator(); @@ -374,6 +373,7 @@ public class Netty4Transport extends TcpTransport { channels[i] = future.channel(); channels[i].closeFuture().addListener(new ChannelCloseListener(node)); } + assert iterator.hasNext() == false : "not all created connection have been consumed"; } catch (final RuntimeException e) { for (final ChannelFuture future : Collections.unmodifiableList(connections)) { FutureUtils.cancel(future);