diff --git a/server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java b/server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java index eecb6ef0dba..ef2cb83ed90 100644 --- a/server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java +++ b/server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java @@ -419,14 +419,6 @@ final class RemoteClusterConnection implements TransportConnectionListener, Clos } if (seedNodes.hasNext()) { - final DiscoveryNode seedNode = maybeAddProxyAddress(proxyAddress, seedNodes.next().get()); - logger.debug("[{}] opening connection to seed node: [{}] proxy address: [{}]", clusterAlias, seedNode, - proxyAddress); - final ConnectionProfile profile = ConnectionProfile.buildSingleChannelProfile(TransportRequestOptions.Type.REG); - - final StepListener openConnectionStep = new StepListener<>(); - connectionManager.openConnection(seedNode, profile, openConnectionStep); - final Consumer onFailure = e -> { if (e instanceof ConnectTransportException || e instanceof IOException || @@ -443,6 +435,17 @@ final class RemoteClusterConnection implements TransportConnectionListener, Clos listener.onFailure(e); }; + final DiscoveryNode seedNode = maybeAddProxyAddress(proxyAddress, seedNodes.next().get()); + logger.debug("[{}] opening connection to seed node: [{}] proxy address: [{}]", clusterAlias, seedNode, + proxyAddress); + final ConnectionProfile profile = ConnectionProfile.buildSingleChannelProfile(TransportRequestOptions.Type.REG); + final StepListener openConnectionStep = new StepListener<>(); + try { + connectionManager.openConnection(seedNode, profile, openConnectionStep); + } catch (Exception e) { + onFailure.accept(e); + } + final StepListener handShakeStep = new StepListener<>(); openConnectionStep.whenComplete(connection -> { ConnectionProfile connectionProfile = connectionManager.getConnectionProfile();