From 04b23a8fab475e2139c875f9ce8001795f7fe964 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 8 Aug 2013 13:10:13 +0200 Subject: [PATCH] Catch RejectedExecutionException on node shutdown --- .../transport/TransportService.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/elasticsearch/transport/TransportService.java b/src/main/java/org/elasticsearch/transport/TransportService.java index 8a29527949f..6ebf70ba63c 100644 --- a/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/src/main/java/org/elasticsearch/transport/TransportService.java @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.atomic.AtomicLong; @@ -292,25 +293,29 @@ public class TransportService extends AbstractLifecycleComponent entry : clientHandlers.entrySet()) { - RequestHolder holder = entry.getValue(); - if (holder.node().equals(node)) { - final RequestHolder holderToNotify = clientHandlers.remove(entry.getKey()); - if (holderToNotify != null) { - // callback that an exception happened, but on a different thread since we don't - // want handlers to worry about stack overflows - threadPool.generic().execute(new Runnable() { - @Override - public void run() { - holderToNotify.handler().handleException(new NodeDisconnectedException(node, holderToNotify.action())); - } - }); + try { + for (TransportConnectionListener connectionListener : connectionListeners) { + connectionListener.onNodeDisconnected(node); + } + // node got disconnected, raise disconnection on possible ongoing handlers + for (Map.Entry entry : clientHandlers.entrySet()) { + RequestHolder holder = entry.getValue(); + if (holder.node().equals(node)) { + final RequestHolder holderToNotify = clientHandlers.remove(entry.getKey()); + if (holderToNotify != null) { + // callback that an exception happened, but on a different thread since we don't + // want handlers to worry about stack overflows + threadPool.generic().execute(new Runnable() { + @Override + public void run() { + holderToNotify.handler().handleException(new NodeDisconnectedException(node, holderToNotify.action())); + } + }); + } } } + } catch (RejectedExecutionException ex) { + logger.debug("Rejected execution on NodeDisconnected", ex); } } });