From 6e9a2ccab4993b6fa19cf4d32caecb7863b0dad0 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 20 Sep 2017 17:53:12 +0200 Subject: [PATCH] Catch exceptions and inform handler in RemoteClusterConnection#collectNodes (#26725) This adds a missing catch block to invoke the action listener instead of bubbeling up the exception. Closes #26700 --- .../transport/RemoteClusterConnection.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java b/core/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java index 39fb515984f7a..c08bf9b737e95 100644 --- a/core/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java +++ b/core/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java @@ -230,15 +230,19 @@ public String executor() { } }); }; - if (connectedNodes.size() == 0) { - // just in case if we are not connected for some reason we try to connect and if we fail we have to notify the listener - // this will cause some back pressure on the search end and eventually will cause rejections but that's fine - // we can't proceed with a search on a cluster level. - // in the future we might want to just skip the remote nodes in such a case but that can already be implemented on the - // caller end since they provide the listener. - ensureConnected(ActionListener.wrap((x) -> runnable.run(), listener::onFailure)); - } else { - runnable.run(); + try { + if (connectedNodes.size() == 0) { + // just in case if we are not connected for some reason we try to connect and if we fail we have to notify the listener + // this will cause some back pressure on the search end and eventually will cause rejections but that's fine + // we can't proceed with a search on a cluster level. + // in the future we might want to just skip the remote nodes in such a case but that can already be implemented on the + // caller end since they provide the listener. + ensureConnected(ActionListener.wrap((x) -> runnable.run(), listener::onFailure)); + } else { + runnable.run(); + } + } catch (Exception ex) { + listener.onFailure(ex); } }