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
case 1 -> getBlobContainer().compareAndExchangeRegister(
                                    OperationPurpose.REPOSITORY_ANALYSIS,
                                    registerName,
                                    bytesFromLong(expectedFinalRegisterValue),
                                    new BytesArray(new byte[] { (byte) 0xff }),
                                    listener
                                );
                                case 2 -> getBlobContainer().compareAndSetRegister(
                                    OperationPurpose.REPOSITORY_ANALYSIS,
                                    registerName,
                                    bytesFromLong(expectedFinalRegisterValue),
                                    new BytesArray(new byte[] { (byte) 0xff }),
                                    listener.map(
                                        b -> b
                                            ? OptionalBytesReference.of(bytesFromLong(expectedFinalRegisterValue))
                                            : OptionalBytesReference.MISSING
                                    )
                                );
                                default -> {
                                    assert false;
                                    throw new IllegalStateException();
                                }
                            }
                        }));
                } else {
                    ref.close();
                }
            };
        }
        private class UncontendedRegisterAnalysis implements Runnable {