{"record":{"id":"0844e3a6e023a4d5","repo":"apache/iceberg","slug":"failed-to-find-sync-past-position-d","errorCode":null,"errorMessage":"Failed to find sync past position %d","messagePattern":"Failed to find sync past position (.+?)","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/avro/AvroIterable.java","lineNumber":128,"sourceCode":"          // Ignore close exception\n        }\n      }\n      throw new RuntimeIOException(e, \"Failed to open file: %s\", file.location());\n    }\n  }\n\n  private static class AvroRangeIterator<D> implements FileReader<D> {\n    private final FileReader<D> reader;\n    private final long end;\n\n    AvroRangeIterator(FileReader<D> reader, long start, long end) {\n      this.reader = reader;\n      this.end = end;\n\n      try {\n        reader.sync(start);\n      } catch (IOException e) {\n        throw new RuntimeIOException(e, \"Failed to find sync past position %d\", start);\n      }\n    }\n\n    @Override\n    public Schema getSchema() {\n      return reader.getSchema();\n    }\n\n    @Override\n    public boolean hasNext() {\n      try {\n        return reader.hasNext() && !reader.pastSync(end);\n      } catch (IOException e) {\n        throw new RuntimeIOException(e, \"Failed to check range end: %d\", end);\n      }\n    }\n\n    @Override","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/avro/AvroIterable.java#L110-L146","documentation":"AvroRangeIterator reads only a byte range [start, end) of an Avro file. On construction it calls reader.sync(start) to align to the first block boundary at or after start. An IOException here means the reader could not find a sync marker past the requested start position, so the range cannot be read reliably.","triggerScenarios":"Constructing an AvroIterable with a start offset beyond or too close to the end of the file, or with a start value computed from stale metadata so that reader.sync() cannot locate a valid sync marker (truncated file, wrong offsets from a rewritten file).","commonSituations":"Task split offsets computed from an old snapshot after the file was compacted; passing start > file size due to a bug in split computation; reading a range of a file that was appended to by a non-Iceberg writer.","solutions":["Recompute the split/range offsets from the current manifest (file content offsets in the DataFile), not cached values","Validate that 0 <= start < file lengthInBytes before building the iterable","Re-open the file and retry in case of transient read corruption during footer sync lookup","Re-verify the file's integrity; if offsets no longer match the file, re-plan the scan"],"exampleFix":"// before: offsets from stale split\nAvroIterable<Record> it = Avro.read(in).project(schema).createReaderFunc(...).split(staleStart, length).build();\n// after: validate against current file metadata\nlong len = in.getLength();\nlong start = Math.min(splitStart, len);\nPreconditions.checkArgument(start >= 0 && start < len, \"Invalid range start %s for file of length %s\", start, len);\nAvroIterable<Record> it = Avro.read(in).project(schema).createReaderFunc(...).split(start, len - start).build();","handlingStrategy":"validation","validationCode":"long len = inputFile.getLength();\nPreconditions.checkArgument(start >= 0 && start < len,\n    \"Range start %s out of bounds for file of length %s\", start, len);","typeGuard":null,"tryCatchPattern":"try (AvroIterable<D> it = buildRangeIterable(start, end)) {\n  it.forEach(consumer);\n} catch (RuntimeIOException e) {\n  replanAndReread();\n}","preventionTips":["Derive split offsets only from the DataFile offsets recorded in the manifest","Recompute splits after any table commit rather than caching offsets","Clamp/validate start offsets against current file length","Do not append to files managed by Iceberg with external writers"],"tags":["avro","io","offset","sync"],"backgroundTag":"invalid-argument-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}