Skip to content

Commit 3f38463

Browse files
authored
Guard open connection call in RemoteClusterConnection (#44921)
Fixes an issue where a call to openConnection was not properly guarded, allowing an exception to bubble up to the uncaught exception handler, causing test failures. Closes #44912
1 parent 20284b8 commit 3f38463

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,6 @@ private void collectRemoteNodes(Iterator<Supplier<DiscoveryNode>> seedNodes, Act
432432
}
433433

434434
if (seedNodes.hasNext()) {
435-
final DiscoveryNode seedNode = maybeAddProxyAddress(proxyAddress, seedNodes.next().get());
436-
logger.debug("[{}] opening connection to seed node: [{}] proxy address: [{}]", clusterAlias, seedNode,
437-
proxyAddress);
438-
final ConnectionProfile profile = ConnectionProfile.buildSingleChannelProfile(TransportRequestOptions.Type.REG);
439-
440-
final StepListener<Transport.Connection> openConnectionStep = new StepListener<>();
441-
connectionManager.openConnection(seedNode, profile, openConnectionStep);
442-
443435
final Consumer<Exception> onFailure = e -> {
444436
if (e instanceof ConnectTransportException ||
445437
e instanceof IOException ||
@@ -456,6 +448,17 @@ private void collectRemoteNodes(Iterator<Supplier<DiscoveryNode>> seedNodes, Act
456448
listener.onFailure(e);
457449
};
458450

451+
final DiscoveryNode seedNode = maybeAddProxyAddress(proxyAddress, seedNodes.next().get());
452+
logger.debug("[{}] opening connection to seed node: [{}] proxy address: [{}]", clusterAlias, seedNode,
453+
proxyAddress);
454+
final ConnectionProfile profile = ConnectionProfile.buildSingleChannelProfile(TransportRequestOptions.Type.REG);
455+
final StepListener<Transport.Connection> openConnectionStep = new StepListener<>();
456+
try {
457+
connectionManager.openConnection(seedNode, profile, openConnectionStep);
458+
} catch (Exception e) {
459+
onFailure.accept(e);
460+
}
461+
459462
final StepListener<TransportService.HandshakeResponse> handShakeStep = new StepListener<>();
460463
openConnectionStep.whenComplete(connection -> {
461464
ConnectionProfile connectionProfile = connectionManager.getConnectionProfile();

0 commit comments

Comments
 (0)