apache/beam · error · IOException

Unable to read file(s) after retrying

Error message

Unable to read file(s) after retrying %d times

What it means

ExplicitShardedFile.readFilesWithRetries reads all shards of an explicitly-sharded file, retrying up to MAX_READ_RETRIES times with exponential backoff. If every attempt throws (missing files, transient filesystem/IO errors, permissions), it gives up and wraps the last IOException in this message. The causing exception is attached as the cause.

Solutions

  1. Inspect the chained cause (lastException) to see the real per-attempt error and fix that root cause first
  2. Verify the shard paths exist and are readable from the pipeline's service account/credentials
  3. For cloud storage, check for rate limiting or transient outages and retry the pipeline after backoff
  4. Increase MAX_READ_RETRIES or the backoff configuration if the failure is genuinely transient

Example fix

// before
List<String> lines = new ExplicitShardedFile("gs://bucket/wrong-prefix/shard-*").readFilesWithRetries();
// after
String pattern = "gs://bucket/correct-prefix/shard-*"; // verified with FileSystems.match()
List<String> lines = new ExplicitShardedFile(pattern).readFilesWithRetries();
Defensive patterns

Strategy: retry

Validate before calling

MatchResult r = FileSystems.match(shardedFile.toString());
if (r.status() != MatchResult.Status.OK || r.metadata().isEmpty()) {
  throw new IllegalStateException("No shards found for pattern before read: " + shardedFile);
}

Try / catch

try {
  lines = shardedFile.readFilesWithRetries();
} catch (IOException e) {
  LOG.error("Shard read exhausted retries; cause: {}", e.getCause(), e);
  throw new RuntimeException("Unreadable shards for " + shardedFile, e);
}

Prevention

When it happens

Trigger: Calling readFilesWithRetries() when the underlying FileSystem keeps throwing IOException for the full retry budget: file(s) deleted mid-run, GCS/S3 throttling or auth failures, wrong path, or network outage persisting longer than the backoff window.

Common situations: Streaming pipelines reading intermediate files from cloud storage during transient outages; typos in shard paths so matches are empty/404; GCS 429/503 rate limits exceeding the retry window; credentials expiring between retries.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/d2b042703675bde5. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/util/ExplicitShardedFile.java:88

      throws IOException, InterruptedException {
    if (files.isEmpty()) {
      return Collections.emptyList();
    }

    IOException lastException = null;

    do {
      try {
        // Read data from file paths
        return readLines(files);
      } catch (IOException e) {
        // Ignore and retry
        lastException = e;
        LOG.warn("Error in file reading. Ignore and retry.");
      }
    } while (BackOffUtils.next(sleeper, backOff));
    // Failed after max retries
    throw new IOException(
        String.format("Unable to read file(s) after retrying %d times", MAX_READ_RETRIES),
        lastException);
  }

  /**
   * Discovers all shards of this file.
   *
   * <p>Because of eventual consistency, reads may discover no files or fewer files than the shard
   * template implies. In this case, the read is considered to have failed.
   */
  public List<String> readFilesWithRetries() throws IOException, InterruptedException {
    return readFilesWithRetries(Sleeper.DEFAULT, BACK_OFF_FACTORY.backoff());
  }

  @Override
  public String toString() {
    return String.format("explicit sharded file (%s)", Joiner.on(", ").join(files));
  }

View on GitHub (pinned to 12126d8942)