{"record":{"id":"2e88848cd29f2086","repo":"apache/iceberg","slug":"failed-to-delete-file-s-2e8884","errorCode":null,"errorMessage":"Failed to delete file: %s","messagePattern":"Failed to delete file: (.+?)","errorType":"exception","errorClass":"RuntimeIOException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/hadoop/HadoopFileIO.java","lineNumber":103,"sourceCode":"\n  @Override\n  public InputFile newInputFile(String path, long length) {\n    return HadoopInputFile.fromLocation(path, length, getConf());\n  }\n\n  @Override\n  public OutputFile newOutputFile(String path) {\n    return HadoopOutputFile.fromPath(new Path(path), getConf());\n  }\n\n  @Override\n  public void deleteFile(String path) {\n    Path toDelete = new Path(path);\n    FileSystem fs = Util.getFs(toDelete, getConf());\n    try {\n      fs.delete(toDelete, false /* not recursive */);\n    } catch (IOException e) {\n      throw new RuntimeIOException(e, \"Failed to delete file: %s\", path);\n    }\n  }\n\n  @Override\n  public Map<String, String> properties() {\n    return properties.immutableMap();\n  }\n\n  @Override\n  public void setConf(Configuration conf) {\n    this.hadoopConf = new SerializableConfiguration(conf);\n  }\n\n  @Override\n  public Configuration getConf() {\n    // Create a default hadoopConf as it is required for the object to be valid.\n    // E.g. newInputFile would throw NPE with getConf() otherwise.\n    if (hadoopConf == null) {","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/hadoop/HadoopFileIO.java#L85-L121","documentation":"HadoopFileIO.deleteFile deletes a single (non-directory) file at the given path using FileSystem.delete(path, false). Any IOException from the underlying filesystem — permission problems, missing credentials, network errors — is wrapped in this RuntimeIOException naming the path.","triggerScenarios":"Calling deleteFile(path) when the filesystem throws IOException: no permission to delete, HDFS unavailable, S3/GCS auth failure, or the file was already removed concurrently (some FS implementations report this as IOException rather than returning false).","commonSituations":"Expired cloud credentials mid-job; deleteOrphanFiles cleanup racing with another writer; HDFS in safe mode; region/bucket misconfiguration so the FS client cannot reach the storage backend.","solutions":["Inspect the wrapped cause via getCause() for the concrete FileSystem error and address it (credentials, permissions, connectivity).","Verify the file still exists before deleting if concurrent deletes are possible.","Confirm the configured Hadoop conf for HadoopFileIO has correct fs.<scheme>.impl and auth settings.","Retry after transient network/HDFS issues; use idempotent cleanup that tolerates already-deleted files."],"exampleFix":"// before\nio.deleteFile(\"hdfs://nn/warehouse/db/table/data-0001.parquet\");\n// after\ntry {\n  io.deleteFile(path);\n} catch (RuntimeIOException e) {\n  if (io.newInputFile(path).exists()) throw e; // genuinely failed\n  LOG.info(\"File already deleted: {}\", path);\n}","handlingStrategy":"try-catch","validationCode":"InputFile check = io.newInputFile(path);\nboolean exists = check.exists(); // cheap pre-check before delete","typeGuard":null,"tryCatchPattern":"try {\n  io.deleteFile(path);\n} catch (RuntimeIOException e) {\n  LOG.error(\"Delete failed for {}: cause={}\", path, e.getCause());\n  // retry on transient causes; skip if file already absent\n}","preventionTips":["Pre-check file existence when concurrent deleters exist.","Keep cloud credentials valid for the whole job duration.","Run orphan-file cleanup exclusively, not concurrently with writers."],"tags":["io","filesystem","file-deletion","hadoop"],"backgroundTag":"file-delete-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"}