**Build scan:**
https://gradle-enterprise.elastic.co/s/vvbkwrzc672ea/tests/:x-pack:plugin:snapshot-based-recoveries:internalClusterTest/org.elasticsearch.xpack.snapshotbasedrecoveries.recovery.SnapshotBasedIndexRecoveryIT/testCancelledRecoveryAbortsDownloadPromptly

**Reproduction line:**
```
./gradlew ':x-pack:plugin:snapshot-based-recoveries:internalClusterTest' --tests "org.elasticsearch.xpack.snapshotbasedrecoveries.recovery.SnapshotBasedIndexRecoveryIT.testCancelledRecoveryAbortsDownloadPromptly" -Dtests.seed=DB2B89F27A651CDB -Dtests.locale=is -Dtests.timezone=Asia/Barnaul -Druntime.java=20
```

**Applicable branches:**
main

**Reproduces locally?:**
Didn't try

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.xpack.snapshotbasedrecoveries.recovery.SnapshotBasedIndexRecoveryIT&tests.test=testCancelledRecoveryAbortsDownloadPromptly

**Failure excerpt:**
```
com.carrotsearch.randomizedtesting.UncaughtExceptionError: Captured an uncaught exception in thread: Thread[id=416, name=elasticsearch[node_t0][generic][T#4], state=RUNNABLE, group=TGRP-SnapshotBasedIndexRecoveryIT]

  at __randomizedtesting.SeedInfo.seed([DB2B89F27A651CDB:44A6B186778E6B1E]:0)

  Caused by: java.lang.AssertionError: (No message provided)

    at __randomizedtesting.SeedInfo.seed([DB2B89F27A651CDB]:0)
    at org.junit.Assert.fail(Assert.java:86)
    at org.junit.Assert.assertTrue(Assert.java:41)
    at org.junit.Assert.assertFalse(Assert.java:64)
    at org.junit.Assert.assertFalse(Assert.java:74)
    at org.elasticsearch.xpack.snapshotbasedrecoveries.recovery.SnapshotBasedIndexRecoveryIT$1.beforeRead(SnapshotBasedIndexRecoveryIT.java:705)
    at org.elasticsearch.xpack.snapshotbasedrecoveries.recovery.SnapshotBasedIndexRecoveryIT$1.read(SnapshotBasedIndexRecoveryIT.java:700)
    at org.elasticsearch.index.snapshots.blobstore.SlicedInputStream.read(SlicedInputStream.java:81)
    at java.io.FilterInputStream.read(FilterInputStream.java:119)
    at org.elasticsearch.index.snapshots.blobstore.RateLimitingInputStream.read(RateLimitingInputStream.java:62)
    at java.io.FilterInputStream.read(FilterInputStream.java:119)
    at org.elasticsearch.index.snapshots.blobstore.RateLimitingInputStream.read(RateLimitingInputStream.java:62)
    at java.io.FilterInputStream.read(FilterInputStream.java:119)
    at org.elasticsearch.indices.recovery.RecoveryTarget$1.read(RecoveryTarget.java:600)
    at java.io.FilterInputStream.read(FilterInputStream.java:95)
    at org.elasticsearch.indices.recovery.MultiFileWriter.writeFile(MultiFileWriter.java:103)
    at org.elasticsearch.indices.recovery.RecoveryTarget.restoreFileFromSnapshot(RecoveryTarget.java:590)
    at org.elasticsearch.indices.recovery.PeerRecoveryTargetService$2.handleRequest(PeerRecoveryTargetService.java:141)
    at org.elasticsearch.indices.recovery.PeerRecoveryTargetService$2.handleRequest(PeerRecoveryTargetService.java:138)
    at org.elasticsearch.indices.recovery.PeerRecoveryTargetService$RecoveryRequestHandler.messageReceived(PeerRecoveryTargetService.java:571)
    at org.elasticsearch.indices.recovery.PeerRecoveryTargetService$RecoveryRequestHandler.messageReceived(PeerRecoveryTargetService.java:558)
    at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:74)
    at org.elasticsearch.transport.InboundHandler$1.doRun(InboundHandler.java:315)
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.lang.Thread.run(Thread.java:1623)

```
x-pack/plugin/snapshot-based-recoveries/src/internalClusterTest/java/org/elasticsearch/xpack/snapshotbasedrecoveries/recovery/SnapshotBasedIndexRecoveryIT.java
);
        AtomicInteger numDocs = new AtomicInteger(randomIntBetween(1, 1000));
        indexDocs(indexName, 0, numDocs.get());
        String repoName = "repo";
        createRepo(repoName, TestRepositoryPlugin.INSTRUMENTED_TYPE);
        createSnapshot(repoName, "snap", Collections.singletonList(indexName));
        long snapshotSizeForIndex = getSnapshotSizeForIndex(repoName, "snap", indexName);
        setReplicaCount(1, indexName);
        boolean waitForSnapshotDownloadToStart = randomBoolean();
        if (waitForSnapshotDownloadToStart) {
            
            assertBusy(() -> {
                RecoveryState recoveryState = getLatestPeerRecoveryStateForShard(indexName, 0);
                assertThat(recoveryState.getIndex().recoveredBytes(), greaterThan(0L));
            });
        }
        
        assertBusy(() -> {
            if (randomBoolean()) {
                int moreDocs = between(1, 5);
                indexDocs(indexName, numDocs.getAndAdd(moreDocs), moreDocs);
            }
            RecoveryState recoveryState = getLatestPeerRecoveryStateForShard(indexName, 0);
            assertThat(recoveryState.getStage(), equalTo(RecoveryState.Stage.DONE));
        });
        ensureGreen(indexName);
        if (waitForSnapshotDownloadToStart) {
            
            RecoveryState recoveryState = getLatestPeerRecoveryStateForShard(indexName, 0);
            assertThat(recoveryState.getIndex().recoveredFromSnapshotBytes(), equalTo(snapshotSizeForIndex));