From ccd819229da7d28655188cc6fcafd08211debfd1 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 27 Jan 2016 17:04:26 +0100 Subject: [PATCH] ensure we don't fail if the executor is shut down --- .../util/concurrent/EsThreadPoolExecutor.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 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 3663737195e..6d94fec17d7 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 @@ -151,7 +151,7 @@ public class EsThreadPoolExecutor extends ThreadPoolExecutor { return runnable; } - private static class FilterAbstractRunnable extends AbstractRunnable { + private class FilterAbstractRunnable extends AbstractRunnable { private final ThreadContext contextHolder; private final AbstractRunnable in; private final ThreadContext.StoredContext ctx; @@ -184,9 +184,18 @@ public class EsThreadPoolExecutor extends ThreadPoolExecutor { @Override protected void doRun() throws Exception { + boolean started = false; try (ThreadContext.StoredContext ingore = contextHolder.stashContext()){ ctx.restore(); + started = true; in.doRun(); + } catch (IllegalStateException ex) { + if (started || isShutdown() == false) { + throw ex; + } + // if we hit an ISE here we have been shutting down + // this comes from the threadcontext and barfs if + // our threadpool has been shutting down } } @@ -197,7 +206,7 @@ public class EsThreadPoolExecutor extends ThreadPoolExecutor { } - private static class FilterRunnable implements Runnable { + private class FilterRunnable implements Runnable { private final ThreadContext contextHolder; private final Runnable in; private final ThreadContext.StoredContext ctx; @@ -210,9 +219,18 @@ public class EsThreadPoolExecutor extends ThreadPoolExecutor { @Override public void run() { + boolean started = false; try (ThreadContext.StoredContext ingore = contextHolder.stashContext()){ ctx.restore(); + started = true; in.run(); + } catch (IllegalStateException ex) { + if (started || isShutdown() == false) { + throw ex; + } + // if we hit an ISE here we have been shutting down + // this comes from the threadcontext and barfs if + // our threadpool has been shutting down } } @Override