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
cancellationListener.addTimeout(request.getTimeout(), repository.threadPool(), EsExecutors.DIRECT_EXECUTOR_SERVICE);
            cancellationListener.addListener(new CheckForCancelListener());
            final Random random = new Random(request.getSeed());
            final List<DiscoveryNode> nodes = getSnapshotNodes(discoveryNodes);
            if (minClusterTransportVersion.onOrAfter(TransportVersions.V_8_8_0)) {
                final String contendedRegisterName = CONTENDED_REGISTER_NAME_PREFIX + UUIDs.randomBase64UUID(random);
                final AtomicBoolean contendedRegisterAnalysisComplete = new AtomicBoolean();
                try (
                    var registerRefs = new RefCountingRunnable(
                        finalRegisterValueVerifier(
                            contendedRegisterName,
                            random,
                            Releasables.wrap(requestRefs.acquire(), () -> contendedRegisterAnalysisComplete.set(true))
                        )
                    )
                ) {
                    final int registerOperations = Math.max(nodes.size(), request.getConcurrency());
                    for (int i = 0; i < registerOperations; i++) {
                        final ContendedRegisterAnalyzeAction.Request registerAnalyzeRequest = new ContendedRegisterAnalyzeAction.Request(
                            request.getRepositoryName(),
                            blobPath,
                            contendedRegisterName,
                            registerOperations,
                            random.nextInt((registerOperations + 1) * 2)
                        );
                        final DiscoveryNode node = nodes.get(i < nodes.size() ? i : random.nextInt(nodes.size()));
                        final Releasable registerRef = registerRefs.acquire();
                        queue.add(ref -> runContendedRegisterAnalysis(Releasables.wrap(registerRef, ref), registerAnalyzeRequest, node));
                    }
                }