diff --git a/server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java b/server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java index 603b4625ee4..f8fdb342b67 100644 --- a/server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java +++ b/server/src/main/java/org/elasticsearch/transport/RemoteClusterConnection.java @@ -368,8 +368,10 @@ final class RemoteClusterConnection implements TransportConnectionListener, Clos boolean runConnect = false; final ActionListener listener = ContextPreservingActionListener.wrapPreservingContext(connectListener, threadPool.getThreadContext()); + boolean closed; synchronized (mutex) { - if (closed.get()) { + closed = this.closed.get(); + if (closed) { assert listeners.isEmpty(); } else { if (listeners.size() >= MAX_LISTENERS) { @@ -382,7 +384,7 @@ final class RemoteClusterConnection implements TransportConnectionListener, Clos runConnect = listeners.size() == 1; } } - if (closed.get()) { + if (closed) { connectListener.onFailure(new AlreadyClosedException("connect handler is already closed")); return; } diff --git a/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java b/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java index de2c698b7bb..2488551f7d6 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java @@ -655,7 +655,6 @@ public class RemoteClusterConnectionTests extends ESTestCase { } } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/45845") public void testCloseWhileConcurrentlyConnecting() throws IOException, InterruptedException, BrokenBarrierException { List knownNodes = new CopyOnWriteArrayList<>(); try (MockTransportService seedTransport = startTransport("seed_node", knownNodes, Version.CURRENT);