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.
This commit is contained in:
Tim Brooks 2020-02-26 15:03:40 -07:00
parent 8ab74fea58
commit f68917160e
No known key found for this signature in database
GPG Key ID: C2AA3BB91A889E77
3 changed files with 7 additions and 4 deletions

View File

@ -45,7 +45,7 @@ final class RemoteClusterAwareClient extends AbstractClient {
@Override
protected <Request extends ActionRequest, Response extends ActionResponse>
void doExecute(ActionType<Response> action, Request request, ActionListener<Response> listener) {
remoteClusterService.ensureConnected(clusterAlias, ActionListener.wrap(res -> {
remoteClusterService.ensureConnected(clusterAlias, ActionListener.wrap(v -> {
Transport.Connection connection;
if (request instanceof RemoteClusterAwareRequest) {
DiscoveryNode preferredTargetNode = ((RemoteClusterAwareRequest) request).getPreferredTargetNode();

View File

@ -110,7 +110,11 @@ public class RemoteConnectionManager implements ConnectionManager {
@Override
public int size() {
return delegate.size();
// Although we use a delegate instance, we report the connection manager size based on the
// RemoteConnectionManager's knowledge of the connections. This is because there is a brief window
// in between the time when the connection is added to the delegate map, and the time when
// nodeConnected is called.
return this.connections.size();
}
@Override

View File

@ -418,8 +418,7 @@ public class SniffConnectionStrategy extends RemoteConnectionStrategy {
@Override
public void onFailure(Exception e) {
if (e instanceof ConnectTransportException ||
e instanceof IllegalStateException) {
if (e instanceof ConnectTransportException || e instanceof IllegalStateException) {
// ISE if we fail the handshake with an version incompatible node
// fair enough we can't connect just move on
logger.debug(() -> new ParameterizedMessage("failed to connect to node {}", node), e);