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
remoteNode.getAddress()
                                                ),
                                                e
                                            );
                                            listener.onFailure(e);
                                        }
                                    });
                                }
                            } catch (Exception e) {
                                listener.onFailure(e);
                            }
                        }
                        @Override
                        protected void innerOnFailure(Exception e) {
                            
                            
                            
                            logger.warn(() -> "handshake to [" + transportAddress + "] failed", e);
                            IOUtils.closeWhileHandlingException(connection);
                            listener.onFailure(e);
                        }
                    });
                })
            );
        } catch (Exception e) {
            listener.onFailure(e);
        }
    }
}