apache/iceberg · error · UncheckedIOException

Failed to close current writer

Error message

Failed to close current writer

What it means

RollingFileWriter.closeCurrentWriter wraps IOException from closing the underlying data writer in UncheckedIOException. It means the currently open data file could not be flushed/closed (e.g. the output stream failed), and the write is aborted rather than committing a possibly corrupt file.

Source

Thrown at core/src/main/java/org/apache/iceberg/io/RollingFileWriter.java:128

    this.currentFile = newFile();
    this.currentFileRows = 0;
    this.currentWriter = newWriter(currentFile);
  }

  private EncryptedOutputFile newFile() {
    if (spec.isUnpartitioned() || partition == null) {
      return fileFactory.newOutputFile();
    } else {
      return fileFactory.newOutputFile(spec, partition);
    }
  }

  private void closeCurrentWriter() {
    if (currentWriter != null) {
      try {
        currentWriter.close();
      } catch (IOException e) {
        throw new UncheckedIOException("Failed to close current writer", e);
      }

      if (currentFileRows == 0L) {
        // the file may not have been created or cannot be deleted, and it isn't worth failing
        // the job to clean up, skip deleting
        Tasks.foreach(currentFile.encryptingOutputFile())
            .suppressFailureWhenFinished()
            .onFailure(
                (file, exc) ->
                    LOG.warn(
                        "Failed to delete the uncommitted empty file during writer clean up: {}",
                        file,
                        exc))
            .run(io::deleteFile);
      } else {
        addResult(currentWriter.result());
      }

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Check storage connectivity/credentials and retry the failed write task.
  2. Verify sufficient disk space and inode/quota limits on the write volume.
  3. Inspect the wrapped IOException cause for the root storage error (e.g. S3 503, GCS quota).
  4. Re-run the job; if transient throttling is frequent, tune object-store client retry settings.
Defensive patterns

Strategy: retry

Validate before calling

// pre-check storage writability before the job
try (OutputStream os = fileIO.newOutputFile(stagingPath).create()) {
  os.write(1); // fail fast if storage unreachable
}

Try / catch

try {
  writer.close();
} catch (UncheckedIOException e) {
  IOException cause = e.getCause();
  if (isTransient(cause)) { retryTask(); } else { throw e; }
}

Prevention

When it happens

Trigger: Calling write() to roll to a new file or close() at the end of writing, when the underlying Avro/Parquet/ORC writer's close() throws IOException — disk full, network failure to object store, or the output stream already aborted.

Common situations: Object-store throttling or credential expiry mid-write; disk quota exceeded on local executor storage; task preemption killing the underlying stream; transient network partition to storage backend.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/b1510df07530fd5b. Report an issue: GitHub.