**Build scan:**
https://gradle-enterprise.elastic.co/s/w5uoitwbjlubk/tests/:server:test/org.elasticsearch.transport.RemoteClusterConnectionTests/testCloseWhileConcurrentlyConnecting

**Reproduction line:**
```
./gradlew ':server:test' --tests "org.elasticsearch.transport.RemoteClusterConnectionTests.testCloseWhileConcurrentlyConnecting" -Dtests.seed=1D1BC140B0F8A67C -Dtests.locale=sk -Dtests.timezone=Africa/Blantyre -Druntime.java=20
```

**Applicable branches:**
main

**Reproduces locally?:**
No

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.transport.RemoteClusterConnectionTests&tests.test=testCloseWhileConcurrentlyConnecting

**Failure excerpt:**
```
com.carrotsearch.randomizedtesting.UncaughtExceptionError: Captured an uncaught exception in thread: Thread[id=1746, name=Thread-113, state=RUNNABLE, group=TGRP-RemoteClusterConnectionTests]


  Caused by: java.lang.AssertionError: cluster:internal/remote_cluster/handshake

    at __randomizedtesting.SeedInfo.seed([1D1BC140B0F8A67C]:0)
    at org.elasticsearch.transport.InboundAggregator.lambda$new$0(InboundAggregator.java:46)
    at org.elasticsearch.transport.InboundAggregator.initializeRequestState(InboundAggregator.java:197)
    at org.elasticsearch.transport.InboundAggregator.headerReceived(InboundAggregator.java:66)
    at org.elasticsearch.transport.InboundPipeline.forwardFragments(InboundPipeline.java:138)
    at org.elasticsearch.transport.InboundPipeline.doHandleBytes(InboundPipeline.java:121)
    at org.elasticsearch.transport.InboundPipeline.handleBytes(InboundPipeline.java:86)
    at org.elasticsearch.transport.netty4.Netty4MessageInboundHandler.channelRead(Netty4MessageInboundHandler.java:63)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:280)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysPlain(NioEventLoop.java:689)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:652)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.lang.Thread.run(Thread.java:1623)

```
server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java
}
                        });
                        modifyingThreads[i].start();
                    }
                    for (Thread thread : getThreads) {
                        thread.join();
                    }
                    for (Thread thread : modifyingThreads) {
                        thread.join();
                    }
                }
            }
        } finally {
            IOUtils.closeWhileHandlingException(discoverableTransports);
        }
    }
    public void testGetConnection() throws Exception {
        List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
        try (
            MockTransportService seedTransport = startTransport("seed_node", knownNodes, Version.CURRENT, TransportVersion.CURRENT);
            MockTransportService disconnectedTransport = startTransport(
                "disconnected_node",
                knownNodes,
                Version.CURRENT,
                TransportVersion.CURRENT
            )
        ) {
            DiscoveryNode seedNode = seedTransport.getLocalNode();
            knownNodes.add(seedNode);
            DiscoveryNode disconnectedNode = disconnectedTransport.getLocalNode();