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
sizeCount = blobSizes.size();
            assert sizeCount > 0;
            blobsBySize = new int[sizeCount];
            assert invariant();
        }
        List<Long> calculate() {
            
            addBlobsRoughlyEvenly(sizeCount - 1);
            
            while (totalBlobs < blobCount) {
                assert totalBytes <= maxTotalBytes;
                final int minSplitCount = Arrays.stream(blobsBySize).skip(1).allMatch(i -> i <= 1) ? 1 : 2;
                final int splitIndex = IntStream.range(1, sizeCount).filter(i -> blobsBySize[i] >= minSplitCount).reduce(-1, (i, j) -> j);
                assert splitIndex > 0 : "split at " + splitIndex;
                assert blobsBySize[splitIndex] >= minSplitCount;
                final long splitSize = blobSizes.get(splitIndex);
                blobsBySize[splitIndex] -= 1;
                totalBytes -= splitSize;
                totalBlobs -= 1;
                addBlobsRoughlyEvenly(splitIndex - 1);
                assert invariant();
            }
            return getPerBlobSizes();
        }
        private List<Long> getPerBlobSizes() {
            assert invariant();
            final List<Long> perBlobSizes = new ArrayList<>(blobCount);
            for (int sizeIndex = 0; sizeIndex < sizeCount; sizeIndex++) {
                final long size = blobSizes.get(sizeIndex);
                for (int i = 0; i < blobsBySize[sizeIndex]; i++) {