Instead we should use `org.elasticsearch.tasks.CancellableTask#addListener` to add a listener which sets `failure` on cancellation.
x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java
private final Random random;
            private final String registerName;
            private final List<DiscoveryNode> nodes;
            private final AtomicBoolean otherAnalysisComplete;
            private int currentValue; 
            UncontendedRegisterAnalysis(Random random, List<DiscoveryNode> nodes, AtomicBoolean otherAnalysisComplete) {
                this.random = random;
                this.registerName = UNCONTENDED_REGISTER_NAME_PREFIX + UUIDs.randomBase64UUID(random);
                this.nodes = nodes;
                this.otherAnalysisComplete = otherAnalysisComplete;
            }
            private final ActionListener<ActionResponse.Empty> stepListener = new ActionListener<>() {
                @Override
                public void onResponse(ActionResponse.Empty ignored) {
                    currentValue += 1;
                    run();
                }
                @Override
                public void onFailure(Exception e) {
                    fail(e);
                }
            };
            @Override
            public void run() {
                if (isRunning() == false) {
                    return;
                }