From 7ef762c8f0758d08fb136a4fbecf873f0fdb95ec Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 27 Jan 2016 21:06:24 +0100 Subject: [PATCH] Only rethrow exceptions if they are coming from the actual runnable but not if we are shutting down the pool --- .../util/concurrent/EsThreadPoolExecutor.java | 14 ++++++++------ .../threadpool/UpdateThreadPoolSettingsTests.java | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/util/concurrent/EsThreadPoolExecutor.java b/core/src/main/java/org/elasticsearch/common/util/concurrent/EsThreadPoolExecutor.java index 6d94fec17d7..fde8d828295 100644 --- a/core/src/main/java/org/elasticsearch/common/util/concurrent/EsThreadPoolExecutor.java +++ b/core/src/main/java/org/elasticsearch/common/util/concurrent/EsThreadPoolExecutor.java @@ -184,13 +184,14 @@ public class EsThreadPoolExecutor extends ThreadPoolExecutor { @Override protected void doRun() throws Exception { - boolean started = false; + boolean whileRunning = false; try (ThreadContext.StoredContext ingore = contextHolder.stashContext()){ ctx.restore(); - started = true; + whileRunning = true; in.doRun(); + whileRunning = false; } catch (IllegalStateException ex) { - if (started || isShutdown() == false) { + if (whileRunning || isShutdown() == false) { throw ex; } // if we hit an ISE here we have been shutting down @@ -219,13 +220,14 @@ public class EsThreadPoolExecutor extends ThreadPoolExecutor { @Override public void run() { - boolean started = false; + boolean whileRunning = false; try (ThreadContext.StoredContext ingore = contextHolder.stashContext()){ ctx.restore(); - started = true; + whileRunning = true; in.run(); + whileRunning = false; } catch (IllegalStateException ex) { - if (started || isShutdown() == false) { + if (whileRunning || isShutdown() == false) { throw ex; } // if we hit an ISE here we have been shutting down diff --git a/core/src/test/java/org/elasticsearch/threadpool/UpdateThreadPoolSettingsTests.java b/core/src/test/java/org/elasticsearch/threadpool/UpdateThreadPoolSettingsTests.java index 2fe11b5875c..06e20fd31f1 100644 --- a/core/src/test/java/org/elasticsearch/threadpool/UpdateThreadPoolSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/threadpool/UpdateThreadPoolSettingsTests.java @@ -325,7 +325,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase { try { Settings nodeSettings = Settings.settingsBuilder() .put("threadpool." + threadPoolName + ".queue_size", 1000) - .put("name", "testCachedExecutorType").build(); + .put("name", "testShutdownNowInterrupts").build(); threadPool = new ThreadPool(nodeSettings); ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); threadPool.setClusterSettings(clusterSettings);