From f38385ee25725e8ca7631eb852ca16b5b1508da1 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Tue, 28 Apr 2020 17:27:58 +0200 Subject: [PATCH] Fix Leaking Listener When Closing NodeClient (#55676) (#55864) If a node client (or rather its underlying node) is closed then any executions on it will just quietly fail as happens in #55660 via closing the nodes on the test thread and asynchronously using a node client. Closes #55660 --- .../java/org/elasticsearch/transport/TransportService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/transport/TransportService.java b/server/src/main/java/org/elasticsearch/transport/TransportService.java index 41c7a462f17..a577feb6294 100644 --- a/server/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/server/src/main/java/org/elasticsearch/transport/TransportService.java @@ -747,9 +747,11 @@ public class TransportService extends AbstractLifecycleComponent implements Repo timeoutHandler.cancel(); } // callback that an exception happened, but on a different thread since we don't - // want handlers to worry about stack overflows + // want handlers to worry about stack overflows. In the special case of running into a closing node we run on the current + // thread on a best effort basis though. final SendRequestTransportException sendRequestException = new SendRequestTransportException(node, action, e); - threadPool.executor(ThreadPool.Names.GENERIC).execute(new AbstractRunnable() { + final String executor = lifecycle.stoppedOrClosed() ? ThreadPool.Names.SAME : ThreadPool.Names.GENERIC; + threadPool.executor(executor).execute(new AbstractRunnable() { @Override public void onRejection(Exception e) { // if we get rejected during node shutdown we don't wanna bubble it up