{"record":{"id":"5a694741dfdc5933","repo":"apache/iceberg","slug":"failed-to-close-current-writer-5a6947","errorCode":null,"errorMessage":"Failed to close current writer","messagePattern":"Failed to close current writer","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/io/ClusteredWriter.java","lineNumber":120,"sourceCode":"    }\n\n    currentWriter.write(row);\n  }\n\n  @Override\n  public void close() throws IOException {\n    if (!closed) {\n      closeCurrentWriter();\n      this.closed = true;\n    }\n  }\n\n  private void closeCurrentWriter() {\n    if (currentWriter != null) {\n      try {\n        currentWriter.close();\n      } catch (IOException e) {\n        throw new UncheckedIOException(\"Failed to close current writer\", e);\n      }\n\n      addResult(currentWriter.result());\n\n      this.currentWriter = null;\n    }\n  }\n\n  @Override\n  public final R result() {\n    Preconditions.checkState(closed, \"Cannot get result from unclosed writer\");\n    return aggregatedResult();\n  }\n}\n","sourceCodeStart":102,"sourceCodeEnd":135,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/io/ClusteredWriter.java#L102-L135","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\ntry {\n  writer.write(row);\n} catch (UncheckedIOException e) {\n  // silently swallowed\n}\n// after\ntry {\n  writer.write(row);\n} catch (UncheckedIOException e) {\n  LOG.error(\"Writer close failed, aborting task\", e);\n  throw e; // surface so the commit is not attempted\n}","handlingStrategy":"try-catch","validationCode":"// ensure writer inputs are valid and storage reachable before writing\ntry (OutputStream probe = io.newOutputFile(targetPath).create()) { probe.write(0); }","typeGuard":null,"tryCatchPattern":"try {\n  writer.close();\n} catch (UncheckedIOException e) {\n  LOG.error(\"Failed to close clustered writer: {}\", e.getCause().getMessage(), e);\n  throw e; // abort commit; retry task\n}","preventionTips":["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"],"tags":["io","file-write","unchecked-exception"],"backgroundTag":"file-write-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}