apache/iceberg · error · UncheckedIOException
Failed to close current writer
Error message
Failed to close current writer
What it means
ClusteredWriter throws UncheckedIOException when closing the current per-partition file writer fails with an IOException. The close path is critical because writer results (file metadata) are only collected after a successful close, so a failure here means data files may be incomplete or corrupt and the write commit should not proceed.
Source
Thrown at core/src/main/java/org/apache/iceberg/io/ClusteredWriter.java:120
}
currentWriter.write(row);
}
@Override
public void close() throws IOException {
if (!closed) {
closeCurrentWriter();
this.closed = true;
}
}
private void closeCurrentWriter() {
if (currentWriter != null) {
try {
currentWriter.close();
} catch (IOException e) {
throw new UncheckedIOException("Failed to close current writer", e);
}
addResult(currentWriter.result());
this.currentWriter = null;
}
}
@Override
public final R result() {
Preconditions.checkState(closed, "Cannot get result from unclosed writer");
return aggregatedResult();
}
}
View on GitHub (pinned to 86d9c8fc54)
Solutions
- Inspect the wrapped IOException cause to identify the underlying storage failure and fix that (permissions, disk space, network).
- Retry the write job; Iceberg commits are transactional so failed partial files are discarded.
- Check storage endpoint health/quotas and increase timeouts for flaky object stores.
- If reproducible, reduce file sizes/roll settings to shrink the amount of data buffered per writer.
Example fix
// before
try {
writer.write(row);
} catch (UncheckedIOException e) {
// silently swallowed
}
// after
try {
writer.write(row);
} catch (UncheckedIOException e) {
LOG.error("Writer close failed, aborting task", e);
throw e; // surface so the commit is not attempted
} Defensive patterns
Strategy: try-catch
Validate before calling
// ensure writer inputs are valid and storage reachable before writing
try (OutputStream probe = io.newOutputFile(targetPath).create()) { probe.write(0); } Try / catch
try {
writer.close();
} catch (UncheckedIOException e) {
LOG.error("Failed to close clustered writer: {}", e.getCause().getMessage(), e);
throw e; // abort commit; retry task
} Prevention
- Monitor disk space and object-store error rates on write nodes
- Keep table write retry policies enabled (Tasks.retry) for transient IO
- Avoid extremely large files per writer to reduce flush duration
- Inspect the cause chain — the root IOException names the real storage problem
When it happens
Trigger: Calling write() when the clustered writer rolls over to a new partition/roll interval and must close the previous writer, or calling close() at end of write, and currentWriter.close() throws IOException (e.g. underlying filesystem/IO failure, full disk, closed connection).
Common situations: Underlying object store throttling or connection resets during flush; disk full on local scratch; HDFS lease recovery issues; task preempted while writer is mid-flush.
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
- Failed to close manifest reader
- Failed to close entries while caching changes
- Failed to close current writer
- Failed to write json to file: %s
- Failed to create file: %s
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/5a694741dfdc5933.
Report an issue: GitHub.