Browse Source

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
Simon Willnauer 8 years ago
parent
commit
b9c0d4447c

+ 13 - 9
core/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java

@@ -230,15 +230,19 @@ final class RemoteClusterConnection extends AbstractComponent implements Transpo
                     }
                 });
         };
-        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);
         }
     }