{"record":{"id":"ad4870910d8f2a63","repo":"apache/iceberg","slug":"failed-to-close-dvfilewriter","errorCode":null,"errorMessage":"Failed to close dvFileWriter","messagePattern":"Failed to close dvFileWriter","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/io/BaseTaskWriter.java","lineNumber":174,"sourceCode":"        .build();\n  }\n\n  @Override\n  public void close() throws IOException {\n    try {\n      if (dvFileWriter != null) {\n        try {\n          // complete will call close\n          dvFileWriter.close();\n          DeleteWriteResult result = dvFileWriter.result();\n          completedDeleteFiles.addAll(result.deleteFiles());\n          referencedDataFiles.addAll(result.referencedDataFiles());\n        } finally {\n          dvFileWriter = null;\n        }\n      }\n    } catch (IOException e) {\n      throw new UncheckedIOException(\"Failed to close dvFileWriter\", e);\n    }\n  }\n\n  /** Base equality delta writer to write both insert records and equality-deletes. */\n  protected abstract class BaseEqualityDeltaWriter implements Closeable {\n    private final StructProjection structProjection;\n    private final PositionDelete<T> positionDelete;\n    private final StructLike partitionKey;\n    private RollingFileWriter dataWriter;\n    private RollingEqDeleteWriter eqDeleteWriter;\n    private PartitioningWriter<PositionDelete<T>, DeleteWriteResult> posDeleteWriter;\n    private Map<StructLike, PathOffset> insertedRowMap;\n    private boolean closePosDeleteWriter;\n\n    protected BaseEqualityDeltaWriter(StructLike partition, Schema schema, Schema deleteSchema) {\n      this(partition, schema, deleteSchema, DeleteGranularity.PARTITION, null);\n    }\n","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/io/BaseTaskWriter.java#L156-L192","documentation":"BaseTaskWriter's close() closes its internal delete-vector file writer and rethrows any IOException as UncheckedIOException. This surfaces an I/O failure (flush/close to the underlying OutputFile) that happened while finalizing delete-vector files during task completion or abort.","triggerScenarios":"An IOException occurs while closing the DV writer, typically from the underlying OutputFile/stream failing (closed stream, IO provider error, disk/FS error in wrapped FileIO) during complete() or abort().","commonSituations":"Underlying FileIO throwing on close (e.g., mocked InMemory IO closed prematurely, network file systems failing during final flush); closing the task writer twice or after the output stream was already closed elsewhere in custom writer code.","solutions":["Inspect the cause chain (getCause()) for the underlying IOException and fix that root cause in the FileIO or filesystem.","Ensure the task writer is closed exactly once and not after its output streams were independently closed.","Verify the OutputFile location is writable and the FileIO is not already closed when the task writer completes."],"exampleFix":"// before\nFileIO io = ...; io.close(); writer.close(); // IO closed before writer\n// after\nwriter.close(); // finalize writers first\nio.close();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  taskWriter.close();\n} catch (UncheckedIOException e) {\n  LOG.error(\"DV writer close failed\", e.getCause());\n  throw e; // task must fail; fix underlying FileIO\n}","preventionTips":["Close task writers before closing the FileIO they use.","Inspect the IOException cause chain to find the real filesystem failure.","Ensure output locations are writable and streams are not double-closed."],"tags":["io","writer","unchecked-exception","delete-files"],"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-14T16:17:12.679Z"}