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/cluster/metadata/MetadataIndexStateService.java
if (blockedIndices.isEmpty()) {
                task.listener().onResponse(CloseIndexResponse.EMPTY);
            } else {
                threadPool.executor(ThreadPool.Names.MANAGEMENT)
                    .execute(
                        new WaitForClosedBlocksApplied(
                            blockedIndices,
                            task.request,
                            task.listener().delegateFailure((delegate2, verifyResults) -> {
                                clusterService.submitStateUpdateTask(
                                    "close-indices",
                                    new CloseIndicesTask(task.request, blockedIndices, verifyResults, delegate2),
                                    ClusterStateTaskConfig.build(Priority.URGENT),
                                    closesExecutor
                                );
                            })
                        )
                    );
            }
        }
    }
    private record AddBlocksToCloseTask(CloseIndexClusterStateUpdateRequest request, ActionListener<CloseIndexResponse> listener)
        implements
            ClusterStateTaskListener {
        @Override
        public void onFailure(Exception e) {
            listener.onFailure(e);
        }
    }
    private class CloseIndicesExecutor implements ClusterStateTaskExecutor<CloseIndicesTask> {