{"record":{"id":"bd7c86cee6c2e53b","repo":"apache/iceberg","slug":"failed-to-delete-staging-file","errorCode":null,"errorMessage":"Failed to delete staging file: {}","messagePattern":"Failed to delete staging file: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"aliyun/src/main/java/org/apache/iceberg/aliyun/oss/OSSOutputStream.java","lineNumber":163,"sourceCode":"    long contentLength = currentStagingFile.length();\n    if (contentLength == 0) {\n      LOG.debug(\"Skipping empty upload to OSS\");\n      return;\n    }\n\n    LOG.debug(\"Uploading {} staged bytes to OSS\", contentLength);\n    InputStream contentStream = uncheckedInputStream(currentStagingFile);\n    ObjectMetadata metadata = new ObjectMetadata();\n    metadata.setContentLength(contentLength);\n\n    PutObjectRequest request =\n        new PutObjectRequest(uri.bucket(), uri.key(), contentStream, metadata);\n    client.putObject(request);\n  }\n\n  private void cleanUpStagingFiles() {\n    if (!currentStagingFile.delete()) {\n      LOG.warn(\"Failed to delete staging file: {}\", currentStagingFile);\n    }\n  }\n\n  @SuppressWarnings({\"checkstyle:NoFinalizer\", \"Finalize\", \"deprecation\"})\n  @Override\n  protected void finalize() throws Throwable {\n    super.finalize();\n    if (!closed) {\n      close(); // releasing resources is more important than printing the warning.\n      String trace = Joiner.on(\"\\n\\t\").join(Arrays.copyOfRange(createStack, 1, createStack.length));\n      LOG.warn(\"Unclosed output stream created by:\\n\\t{}\", trace);\n    }\n  }\n}\n","sourceCodeStart":145,"sourceCodeEnd":178,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/aliyun/src/main/java/org/apache/iceberg/aliyun/oss/OSSOutputStream.java#L145-L178","documentation":"OSSOutputStream writes data to a local staging file before uploading it to OSS via PutObjectRequest. When the stream is closed, cleanUpStagingFiles() deletes the temp file; if File.delete() fails it logs this warning. The upload itself already succeeded (or the close path handled the error), so this is a leftover temp-file cleanup issue — it can consume local disk if it happens repeatedly.","triggerScenarios":"close() calls cleanUpStagingFiles() and File.delete() returns false — the staging file is locked by another process, already deleted, or the process lacks delete permission on the working directory (java.io.tmpdir or the configured staging location).","commonSituations":"Containers with read-only /tmp; antivirus or backup tools holding the file open on Windows; disk-full or permission problems in the temp dir; concurrent threads sharing the same staging file path.","solutions":["Check filesystem permissions on the staging/tmp directory and grant the process delete rights.","Verify nothing else (scanner, backup, another task) is holding the staging file open; configure an exclusion.","Point the staging location (java.io.tmpdir / worker scratch dir) at a writable, task-local directory.","Add periodic cleanup of stale staging files from crashed tasks to reclaim disk space."],"exampleFix":"// before (worker config)\n# staging inherits /tmp (read-only in container)\n// after\nexport JAVA_TOOL_OPTIONS=\"-Djava.io.tmpdir=/var/tmp/iceberg-staging\" # writable, task-local","handlingStrategy":"validation","validationCode":"Path stagingDir = Path.of(System.getProperty(\"java.io.tmpdir\"));\nif (!Files.isWritable(stagingDir)) {\n  throw new IllegalStateException(\"Staging dir not writable: \" + stagingDir);\n}","typeGuard":null,"tryCatchPattern":"try (OutputStream out = file.create()) {\n  out.write(data);\n} catch (Exception e) {\n  // close() already attempted staging cleanup; log includes the file path\n  LOG.error(\"OSS write failed; check staging dir perms and disk space\", e);\n  throw e;\n}","preventionTips":["Point java.io.tmpdir at a writable, task-local directory in containers.","Ensure the Connect/Spark/Flink process user owns or can delete files in the staging directory.","Exclude the staging dir from antivirus/backup scanners that hold files open.","Schedule cleanup of orphaned staging files after worker crashes to prevent disk exhaustion."],"tags":["aliyun","oss","file-delete","staging","cleanup"],"backgroundTag":"file-write-permission-denied","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"}