From 43617cf5dc80c9da1439bb9fd0000598a3aa1abb Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sun, 16 Mar 2014 07:37:45 +0100 Subject: [PATCH] Count latch down if sendsPing throws exception if the async sendPingsHandler throws an unexpected exception the corresponding latch is never counted down. This might only happen during node shutdown but can still cause starvation or test failures. --- .../zen/ping/unicast/UnicastZenPing.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java b/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java index 63e49747ff8..91e8034c540 100644 --- a/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java +++ b/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java @@ -268,10 +268,11 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen sendPingsHandler.executor().execute(new Runnable() { @Override public void run() { + if (sendPingsHandler.isClosed()) { + return; + } + boolean success = false; try { - if (sendPingsHandler.isClosed()) { - return; - } // connect to the node, see if we manage to do it, if not, bail if (!nodeFoundByAddress) { logger.trace("[{}] connecting (light) to {}", sendPingsHandler.id(), nodeToSend); @@ -289,10 +290,16 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen latch.countDown(); logger.trace("[{}] connect to {} was too long outside of ping window, bailing", sendPingsHandler.id(), node); } + success = true; } catch (ConnectTransportException e) { - // can't connect to the node + // can't connect to the node - this is a more common path! logger.trace("[{}] failed to connect to {}", e, sendPingsHandler.id(), nodeToSend); - latch.countDown(); + } catch (Throwable e) { + logger.warn("[{}] failed send ping to {}", e, sendPingsHandler.id(), nodeToSend); + } finally { + if (!success) { + latch.countDown(); + } } } });