https://github.com/elastic/elasticsearch/blob/099fb84cfcf87be6689c3516674f45438bafa767/server/src/main/java/org/elasticsearch/action/ActionListener.java#L420-L432

Rather than keeping hold of the `delegate` and using an `AtomicBoolean` to track the completion, we could use an `AtomicReference` and drop the whole listener on completion, which might free up heap in some fail-fast cases.
server/src/main/java/org/elasticsearch/discovery/HandshakingTransportAddressConnector.java
null
                ),
                listener.delegateFailure((l, connection) -> {
                    logger.trace("[{}] opened probe connection", transportAddress);
                    
                    
                    transportService.handshake(connection, probeHandshakeTimeout, new NotifyOnceListener<>() {
                        @Override
                        protected void innerOnResponse(DiscoveryNode remoteNode) {
                            try {
                                
                                logger.trace("[{}] handshake successful: {}", transportAddress, remoteNode);
                                IOUtils.closeWhileHandlingException(connection);
                                if (remoteNode.equals(transportService.getLocalNode())) {
                                    listener.onFailure(
                                        new ConnectTransportException(
                                            remoteNode,
                                            String.format(
                                                Locale.ROOT,
                                                "successfully discovered local node %s at [%s]",
                                                remoteNode.descriptionWithoutAttributes(),
                                                transportAddress
                                            )
                                        )
                                    );
                                } else if (remoteNode.isMasterNode() == false) {
                                    listener.onFailure(
                                        new ConnectTransportException(
                                            remoteNode,
                                            String.format(