apache/iceberg · error · UncheckedIOException

Failed to close current writer

Error message

Failed to close current writer

What it means

When FileScopedPositionDeleteWriter rolls to a new data file or closes, it closes the current wrapped writer and collects its DeleteWriteResult. An IOException during that close is rethrown as UncheckedIOException("Failed to close current writer"), because failing to finalize a delete file means its metadata (result) cannot be trusted.

Source

Thrown at core/src/main/java/org/apache/iceberg/deletes/FileScopedPositionDeleteWriter.java:109

  }

  private void openCurrentWriter(CharSequence path) {
    Preconditions.checkState(!closed, "Writer has already been closed");
    this.currentWriter = writers.get();
    this.currentPath = path;
  }

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

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Inspect the wrapped cause for the storage error and fix permissions/quota/network
  2. Retry the write job; ensure idempotent staging so partial delete files are discarded
  3. Verify FileIO configuration and storage availability before commit
  4. Check for concurrent cleanup processes removing staging files mid-write

Example fix

// before
try (FileScopedPositionDeleteWriter<R> writer = createWriter()) {
  writer.write(path, pos, row);
} // UncheckedIOException on close
// after
try (FileScopedPositionDeleteWriter<R> writer = createWriter()) {
  writer.write(path, pos, row);
} catch (UncheckedIOException e) {
  LOG.error("Closing position delete writer failed: {}", e.getCause().getMessage());
  abortStagedDeleteFiles();
  throw e;
}
Defensive patterns

Strategy: try-catch

Try / catch

try {
  writer.close();
} catch (UncheckedIOException e) {
  LOG.error("Delete writer close failed: {}", e.getCause().getMessage());
  abort(); // drop staged files, fail the commit
  throw e;
}

Prevention

When it happens

Trigger: Calling write() with a new data path (rolls the writer) or close(), where the underlying file writer's close() throws IOException - e.g. failure flushing/uploading the position-delete file to storage.

Common situations: S3/HDFS write errors (permissions, quota, network) when finalizing delete files; interrupted uploads during commit preparation; disk-full on local staging directories.

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/94a0e037746969c3. Report an issue: GitHub.