**Build scan:**
https://gradle-enterprise.elastic.co/s/2xb4cmauxivio/tests/:x-pack:plugin:security:test/org.elasticsearch.xpack.security.transport.netty4.SecurityNetty4ServerTransportAuthenticationTests/testProxyStrategyConnectionClosesWhenAuthenticatorAlwaysFails

**Reproduction line:**
```
./gradlew ':x-pack:plugin:security:test' --tests "org.elasticsearch.xpack.security.transport.netty4.SecurityNetty4ServerTransportAuthenticationTests.testProxyStrategyConnectionClosesWhenAuthenticatorAlwaysFails" -Dtests.seed=65CEE37A51C3E0A8 -Dtests.locale=nl-BE -Dtests.timezone=Canada/Atlantic -Druntime.java=20
```

**Applicable branches:**
8.10

**Reproduces locally?:**
Didn't try

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.xpack.security.transport.netty4.SecurityNetty4ServerTransportAuthenticationTests&tests.test=testProxyStrategyConnectionClosesWhenAuthenticatorAlwaysFails

**Failure excerpt:**
```
com.carrotsearch.randomizedtesting.UncaughtExceptionError: Captured an uncaught exception in thread: Thread[id=366, name=elasticsearch[org.elasticsearch.xpack.security.transport.netty4.SecurityNetty4ServerTransportAuthenticationTests][generic][T#4], state=RUNNABLE, group=TGRP-SecurityNetty4ServerTransportAuthenticationTests]

  at __randomizedtesting.SeedInfo.seed([65CEE37A51C3E0A8:8A442912B68D27E8]:0)

  Caused by: java.lang.AssertionError: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because the return value of "java.util.concurrent.atomic.AtomicReference.get()" is null

    at __randomizedtesting.SeedInfo.seed([65CEE37A51C3E0A8]:0)
    at org.elasticsearch.action.ActionListenerImplementations.expectNoException(ActionListenerImplementations.java:155)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:68)
    at org.elasticsearch.action.ActionListener$2.onFailure(ActionListener.java:185)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
    at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
    at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
    at org.elasticsearch.action.support.ContextPreservingActionListener.onFailure(ContextPreservingActionListener.java:39)
    at org.elasticsearch.action.ActionListener.onFailure(ActionListener.java:247)
    at org.elasticsearch.transport.RemoteConnectionStrategy$1$1.onFailure(RemoteConnectionStrategy.java:304)
    at org.elasticsearch.transport.ProxyConnectionStrategy$1.onFailure(ProxyConnectionStrategy.java:279)
    at org.elasticsearch.transport.ProxyConnectionStrategy.lambda$openConnections$10(ProxyConnectionStrategy.java:314)
    at org.elasticsearch.action.ActionListenerImplementations$DelegatingResponseActionListener.acceptException(ActionListenerImplementations.java:186)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListenerImplementations$DelegatingResponseActionListener.onFailure(ActionListenerImplementations.java:191)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
    at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
    at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
    at org.elasticsearch.action.support.ContextPreservingActionListener.onFailure(ContextPreservingActionListener.java:39)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
    at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
    at org.elasticsearch.action.support.SubscribableListener$FailureResult.complete(SubscribableListener.java:285)
    at org.elasticsearch.action.support.SubscribableListener.tryComplete(SubscribableListener.java:197)
    at org.elasticsearch.action.support.SubscribableListener.setResult(SubscribableListener.java:222)
    at org.elasticsearch.action.support.SubscribableListener.onFailure(SubscribableListener.java:141)
    at org.elasticsearch.transport.ClusterConnectionManager.failConnectionListener(ClusterConnectionManager.java:388)
    at org.elasticsearch.transport.ClusterConnectionManager.lambda$connectToNodeOrRetry$5(ClusterConnectionManager.java:261)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListener$2.onFailure(ActionListener.java:185)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
    at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
    at org.elasticsearch.action.ActionListenerImplementations$RunAfterActionListener.onFailure(ActionListenerImplementations.java:269)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
    at org.elasticsearch.action.ActionListener$4.onFailure(ActionListener.java:336)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
    at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
    at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
    at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
    at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
    at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:54)
    at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1424)
    at org.elasticsearch.transport.InboundHandler.doHandleException(InboundHandler.java:440)
    at org.elasticsearch.transport.InboundHandler$3.doRun(InboundHandler.java:432)
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.lang.Thread.run(Thread.java:1623)

    Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because the return value of "java.util.concurrent.atomic.AtomicReference.get()" is null

      at org.elasticsearch.xpack.security.transport.netty4.SecurityNetty4ServerTransportAuthenticationTests.lambda$testProxyStrategyConnectionClosesWhenAuthenticatorAlwaysFails$4(SecurityNetty4ServerTransportAuthenticationTests.java:207)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListener$2.onFailure(ActionListener.java:185)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
      at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
      at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
      at org.elasticsearch.action.support.ContextPreservingActionListener.onFailure(ContextPreservingActionListener.java:39)
      at org.elasticsearch.action.ActionListener.onFailure(ActionListener.java:247)
      at org.elasticsearch.transport.RemoteConnectionStrategy$1$1.onFailure(RemoteConnectionStrategy.java:304)
      at org.elasticsearch.transport.ProxyConnectionStrategy$1.onFailure(ProxyConnectionStrategy.java:279)
      at org.elasticsearch.transport.ProxyConnectionStrategy.lambda$openConnections$10(ProxyConnectionStrategy.java:314)
      at org.elasticsearch.action.ActionListenerImplementations$DelegatingResponseActionListener.acceptException(ActionListenerImplementations.java:186)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListenerImplementations$DelegatingResponseActionListener.onFailure(ActionListenerImplementations.java:191)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
      at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
      at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
      at org.elasticsearch.action.support.ContextPreservingActionListener.onFailure(ContextPreservingActionListener.java:39)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
      at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
      at org.elasticsearch.action.support.SubscribableListener$FailureResult.complete(SubscribableListener.java:285)
      at org.elasticsearch.action.support.SubscribableListener.tryComplete(SubscribableListener.java:197)
      at org.elasticsearch.action.support.SubscribableListener.setResult(SubscribableListener.java:222)
      at org.elasticsearch.action.support.SubscribableListener.onFailure(SubscribableListener.java:141)
      at org.elasticsearch.transport.ClusterConnectionManager.failConnectionListener(ClusterConnectionManager.java:388)
      at org.elasticsearch.transport.ClusterConnectionManager.lambda$connectToNodeOrRetry$5(ClusterConnectionManager.java:261)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListener$2.onFailure(ActionListener.java:185)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
      at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
      at org.elasticsearch.action.ActionListenerImplementations$RunAfterActionListener.onFailure(ActionListenerImplementations.java:269)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
      at org.elasticsearch.action.ActionListener$4.onFailure(ActionListener.java:336)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
      at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
      at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
      at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
      at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
      at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:54)
      at org.elasticsearch.transport.TransportService$ContextRestoreResponseHandler.handleException(TransportService.java:1424)
      at org.elasticsearch.transport.InboundHandler.doHandleException(InboundHandler.java:440)
      at org.elasticsearch.transport.InboundHandler$3.doRun(InboundHandler.java:432)
      at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)
      at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
      at java.lang.Thread.run(Thread.java:1623)

```
x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4ServerTransportAuthenticationTests.java
threadPool,
            new NetworkService(List.of()),
            PageCacheRecycler.NON_RECYCLING_INSTANCE,
            new NamedWriteableRegistry(List.of()),
            new NoneCircuitBreakerService(),
            null,
            mock(SSLService.class),
            new SharedGroupFactory(remoteSettings),
            remoteCrossClusterAccessAuthenticationService
        );
        remoteTransportService = MockTransportService.createNewService(
            remoteSettings,
            remoteSecurityNetty4ServerTransport,
            VersionInformation.CURRENT,
            threadPool,
            null,
            Collections.emptySet(),
            
            
            new TransportInterceptor() {
                @Override
                public <T extends TransportRequest> TransportRequestHandler<T> interceptHandler(
                    String action,
                    Executor executor,
                    boolean forceExecution,
                    TransportRequestHandler<T> actualHandler
                ) {
                    return (request, channel, task) -> {
                        Exception authnException = authenticationException.get();
                        if (authnException != null) {