{"record":{"id":"5d81c7c7fa9cfa59","repo":"apache/beam","slug":"unable-to-read-file-s-after-retrying-d-times-5d81c7","errorCode":null,"errorMessage":"Unable to read file(s) after retrying %d times","messagePattern":"Unable to read file\\(s\\) after retrying (.+?) times","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/FilePatternMatchingShardedFile.java","lineNumber":108,"sourceCode":"            \"Found file(s) {} by matching the path: {}\",\n            files.stream()\n                .map(Metadata::resourceId)\n                .map(ResourceId::getFilename)\n                .collect(Collectors.joining(\",\")),\n            filePattern);\n        if (files.isEmpty()) {\n          continue;\n        }\n        // Read data from file paths\n        return readLines(files);\n      } catch (IOException e) {\n        // Ignore and retry\n        lastException = e;\n        LOG.warn(\"Error in file reading. Ignore and retry.\");\n      }\n    } while (BackOffUtils.next(sleeper, backOff));\n    // Failed after max retries\n    throw new IOException(\n        String.format(\"Unable to read file(s) after retrying %d times\", MAX_READ_RETRIES),\n        lastException);\n  }\n\n  /** Discovers all shards of this file. */\n  public List<String> readFilesWithRetries() throws IOException, InterruptedException {\n    return readFilesWithRetries(Sleeper.DEFAULT, BACK_OFF_FACTORY.backoff());\n  }\n\n  @Override\n  public String toString() {\n    return String.format(\"sharded file matching pattern: %s\", filePattern);\n  }\n\n  /**\n   * Reads all the lines of all the files.\n   *\n   * <p>Not suitable for use except in testing of small data, since the data size may be far more","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/FilePatternMatchingShardedFile.java#L90-L126","documentation":"FilePatternMatchingShardedFile.readFilesWithRetries discovers shards matching a file pattern and reads them, retrying up to MAX_READ_RETRIES times with exponential backoff. If all attempts fail (or the output directory stays empty), it throws this IOException with the last per-attempt exception attached as cause.","triggerScenarios":"Calling readFilesWithRetries() when the file pattern matches nothing (empty output dir) or every read attempt throws IOException for the entire backoff window — e.g. writer job never produced shards, wrong pattern, or persistent storage errors.","commonSituations":"Runner-side reads of write-then-read intermediate data where the upstream write failed silently; file pattern typo (wrong stage/output directory); GCS/S3 throttling; eventual consistency delays where shards aren't visible yet.","solutions":["Check the chained cause for the underlying per-attempt error and fix that","Verify the file pattern matches existing shards (use FileSystems.match(pattern) to test)","Confirm the upstream job actually completed and wrote the expected shards before reading","If failures are transient (throttling), rerun later or increase retry budget"],"exampleFix":"// before\nFilePatternMatchingShardedFile f = new FilePatternMatchingShardedFile(\"gs://bucket/missing-output/*\");\nList<String> lines = f.readFilesWithRetries();\n// after\nMatchResult match = FileSystems.match(\"gs://bucket/actual-output/*\");\nif (match.status() == MatchResult.Status.OK && !match.metadata().isEmpty()) {\n  List<String> lines = new FilePatternMatchingShardedFile(\"gs://bucket/actual-output/*\").readFilesWithRetries();\n}","handlingStrategy":"validation","validationCode":"MatchResult r = FileSystems.match(filePattern);\nif (r.status() != MatchResult.Status.OK || r.metadata().isEmpty()) {\n  throw new IllegalStateException(\"File pattern matched no shards: \" + filePattern);\n}","typeGuard":null,"tryCatchPattern":"try {\n  lines = shardedFile.readFilesWithRetries();\n} catch (IOException e) {\n  LOG.error(\"Read failed after retries. Root cause: {}\", e.getCause(), e);\n  throw e;\n}","preventionTips":["Confirm the upstream write stage completed before reading its output","Test the file pattern with FileSystems.match in a precheck step","Watch for eventual-consistency lag on object stores when reading fresh output"],"tags":["java","io","file-read","retry-exhausted"],"backgroundTag":"file-read-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}