Skip to content

Commit f689171

Browse files
committed
Fix RemoteConnectionManager size() method (#52823)
Currently the remote connection manager will delegate the size() call to the underlying cluster connection manager. This introduces the possibility that call will return 1 before the nodeConnection method has been triggered to add the connection to the remote connection list. This can cause issues, as the ensureConnected method checks the connection managers size and executes synchronously if the size is > 0. This leads to a potential cluster not connected exception while we are still waiting for the connection opened callback to be triggered. This commit fixes this issue by using the remote connection manager's size to report the connection manager's size. Fixes #52029.
1 parent 8ab74fe commit f689171

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class RemoteClusterAwareClient extends AbstractClient {
4545
@Override
4646
protected <Request extends ActionRequest, Response extends ActionResponse>
4747
void doExecute(ActionType<Response> action, Request request, ActionListener<Response> listener) {
48-
remoteClusterService.ensureConnected(clusterAlias, ActionListener.wrap(res -> {
48+
remoteClusterService.ensureConnected(clusterAlias, ActionListener.wrap(v -> {
4949
Transport.Connection connection;
5050
if (request instanceof RemoteClusterAwareRequest) {
5151
DiscoveryNode preferredTargetNode = ((RemoteClusterAwareRequest) request).getPreferredTargetNode();

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ public Transport.Connection getAnyRemoteConnection() {
110110

111111
@Override
112112
public int size() {
113-
return delegate.size();
113+
// Although we use a delegate instance, we report the connection manager size based on the
114+
// RemoteConnectionManager's knowledge of the connections. This is because there is a brief window
115+
// in between the time when the connection is added to the delegate map, and the time when
116+
// nodeConnected is called.
117+
return this.connections.size();
114118
}
115119

116120
@Override

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,7 @@ public void onResponse(Void aVoid) {
418418

419419
@Override
420420
public void onFailure(Exception e) {
421-
if (e instanceof ConnectTransportException ||
422-
e instanceof IllegalStateException) {
421+
if (e instanceof ConnectTransportException || e instanceof IllegalStateException) {
423422
// ISE if we fail the handshake with an version incompatible node
424423
// fair enough we can't connect just move on
425424
logger.debug(() -> new ParameterizedMessage("failed to connect to node {}", node), e);

0 commit comments

Comments
 (0)