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 TransportService transportService;
        private final BlobStoreRepository repository;
        private final CancellableTask task;
        private final Request request;
        private final DiscoveryNodes discoveryNodes;
        private final TransportVersion minClusterTransportVersion;
        private final LongSupplier currentTimeMillisSupplier;
        private final ActionListener<Response> listener;
        private final SubscribableListener<Void> cancellationListener;
        private final long timeoutTimeMillis;
        
        private final String blobPath = "temp-analysis-" + UUIDs.randomBase64UUID();
        private final AtomicLong expectedRegisterValue = new AtomicLong();
        private final Queue<Consumer<Releasable>> queue = ConcurrentCollections.newQueue();
        private final AtomicReference<Exception> failure = new AtomicReference<>();
        private final Semaphore innerFailures = new Semaphore(5); 
        private final RefCountingRunnable requestRefs = new RefCountingRunnable(this::runCleanUp);
        private final Set<String> expectedBlobs = ConcurrentCollections.newConcurrentSet();
        private final List<BlobAnalyzeAction.Response> responses;