elastic/elasticsearch · error · IOException

Interrupted while retrying download from: {}

Error message

Interrupted while retrying download from: {}

What it means

Raised by readHttpBytesWithRetry when the thread is interrupted during the inter-attempt backoff sleep. The method re-asserts the interrupt status (Thread.currentThread().interrupt()) and wraps the InterruptedException in an IOException so the checked-interrupt contract is preserved while still failing the download. The offending URL is included.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/util/HttpUtils.java:47

    }

    public static byte[] readHttpBytesWithRetry(String url, int maxAttempts, long baseBackoffMillis, Sleeper sleeper) throws IOException {
        if (maxAttempts <= 0) {
            throw new IllegalArgumentException("maxAttempts must be >= 1 but was [" + maxAttempts + "]");
        }
        if (baseBackoffMillis < 0) {
            throw new IllegalArgumentException("baseBackoffMillis must be >= 0 but was [" + baseBackoffMillis + "]");
        }

        IOException lastException = null;
        for (int attempt = 1; attempt <= maxAttempts; attempt++) {
            if (attempt > 1 && baseBackoffMillis > 0) {
                long backoff = baseBackoffMillis * (attempt - 1);
                try {
                    sleeper.sleep(backoff);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new IOException("Interrupted while retrying download from: " + url, e);
                }
            }

            try (InputStream in = URI.create(url).toURL().openStream()) {
                return in.readAllBytes();
            } catch (IOException e) {
                lastException = e;
            }
        }
        assert lastException != null;
        throw lastException;
    }
}

View on GitHub (pinned to db6a809a66)

Solutions

  1. If the interrupt was unintentional, find the source of Thread.interrupt() / executor shutdown and avoid cancelling the download prematurely.
  2. Treat this as a normal abort: let the IOException propagate and ensure callers release partial resources.
  3. If downloads must be cancellable, design an explicit cancellation flag instead of relying on thread interruption.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    bytes = HttpUtils.readHttpBytesWithRetry(url);
} catch (IOException e) {
    if (Thread.currentThread().isInterrupted()) {
        // download aborted via interrupt; release partial resources, re-flag interrupt
        Thread.currentThread().interrupt();
        throw e;
    }
    // genuine network failure - retry/fallback as needed
}

Prevention

When it happens

Trigger: A Gradle build task or worker thread calling readHttpBytesWithRetry is cancelled (e.g. build aborted, executor shutdown) mid-backoff between HTTP attempts; a test injects an interrupt to abort a hanging download.

Common situations: User cancels a long-running Gradle download task; a worker thread pool is shut down during resource fetching; CI timeout interrupts the build while it retries a flaky URL.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/58de5b27004336e8. Report an issue: GitHub.