{"record":{"id":"58245d5318367d20","repo":"apache/iceberg","slug":"failed-to-get-stream-length","errorCode":null,"errorMessage":"Failed to get stream length","messagePattern":"Failed to get stream length","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/avro/AvroFileAppender.java","lineNumber":85,"sourceCode":"    } catch (IOException e) {\n      throw new RuntimeIOException(e);\n    }\n  }\n\n  @Override\n  public Metrics metrics() {\n    Preconditions.checkState(isClosed, \"Cannot return metrics while appending to an open file.\");\n\n    return AvroMetrics.fromWriter(datumWriter, icebergSchema, numRecords, metricsConfig);\n  }\n\n  @Override\n  public long length() {\n    if (stream != null) {\n      try {\n        return stream.storedLength();\n      } catch (IOException e) {\n        throw new RuntimeIOException(e, \"Failed to get stream length\");\n      }\n    }\n    throw new RuntimeIOException(\"Failed to get stream length: no open stream\");\n  }\n\n  @Override\n  public void close() throws IOException {\n    if (writer != null) {\n      writer.close();\n      this.writer = null;\n      isClosed = true;\n    }\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  private static <D> DataFileWriter<D> newAvroWriter(\n      Schema schema,\n      PositionOutputStream stream,","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/avro/AvroFileAppender.java#L67-L103","documentation":"AvroFileAppender.length() reports the stored length of the underlying output stream. If reading the stored length from the stream throws an IOException, it is rethrown as RuntimeIOException with 'Failed to get stream length'. This typically reflects an I/O failure while querying the stream position, distinct from having no stream at all.","triggerScenarios":"Calling length() on an appender whose OutputFile stream throws on storedLength() — e.g. the underlying file handle is broken, the remote storage call fails, or the stream is in an inconsistent state after an earlier write failure.","commonSituations":"HDFS/S3 connection failures while retrieving file size during manifest writing; a previously failed write leaving the stream unusable; flaky network storage mid-commit.","solutions":["Inspect the cause chain for the underlying IOException and fix the storage access problem","Retry the write/commit operation after restoring connectivity to the storage system","Avoid calling length() after a prior write failure; treat the appender as failed and abort the write","Check storage backend health (HDFS NameNode, S3 endpoint) and credentials"],"exampleFix":"// before\nlong len = appender.length(); // throws after S3 connection drop\n\n// after\nif (!isHealthy(appender)) { abortWrite(); } else { long len = appender.length(); }","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return appender.length(); } catch (RuntimeIOException e) { if (e.getCause() instanceof IOException) { /* retry after storage recovery or abort write */ } throw e; }","preventionTips":["Treat any prior write failure as fatal for the appender","Verify storage backend health before commit","Avoid length() calls on long-idle remote streams"],"tags":["avro","io","stream"],"backgroundTag":"file-read-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}