From e764f413414201d24727f46c696f04a8a2a27522 Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 29 Dec 2010 12:49:37 +0200 Subject: [PATCH] await closing sockets on shutdown --- .../transport/netty/NettyTransport.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java index 84ef8835f13..db09466a988 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java @@ -324,7 +324,7 @@ public class NettyTransport extends AbstractLifecycleComponent implem for (Iterator it = connectedNodes.values().iterator(); it.hasNext();) { NodeChannels nodeChannels = it.next(); it.remove(); - nodeChannels.close(); + nodeChannels.closeAndWait(); } if (clientBootstrap != null) { @@ -615,5 +615,23 @@ public class NettyTransport extends AbstractLifecycleComponent implem } } } + + public void closeAndWait() { + closeChannelsAndWait(low); + closeChannelsAndWait(med); + closeChannelsAndWait(high); + } + + private void closeChannelsAndWait(Channel[] channels) { + for (Channel channel : channels) { + try { + if (channel != null && channel.isOpen()) { + channel.close().awaitUninterruptibly(); + } + } catch (Exception e) { + //ignore + } + } + } } }