{"record":{"id":"bfbc457eba0a9b98","repo":"apache/flink","slug":"failed-to-delete","errorCode":null,"errorMessage":"Failed to delete: {}","messagePattern":"Failed to delete: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/NativeS3FileSystem.java","lineNumber":405,"sourceCode":"\n                s3Client.deleteObject(request);\n                return true;\n            } else {\n                if (!recursive) {\n                    throw new IOException(\"Directory not empty and recursive = false\");\n                }\n\n                final FileStatus[] contents = listStatus(path);\n                for (FileStatus file : contents) {\n                    delete(file.getPath(), true);\n                }\n\n                return true;\n            }\n        } catch (FileNotFoundException e) {\n            return false;\n        } catch (S3Exception e) {\n            throw new IOException(\"Failed to delete: \" + path, e);\n        }\n    }\n\n    /**\n     * Creates a directory at the specified path.\n     *\n     * <p><b>S3 Behavior:</b> S3 is a flat object store and doesn't have true directories. Directory\n     * semantics are simulated through key prefixes. This method always returns true because:\n     *\n     * <ul>\n     *   <li>S3 doesn't require directories to exist before creating objects with that prefix\n     *   <li>Creating an empty \"directory marker\" object (key ending with /) is optional\n     *   <li>Most S3 implementations don't create these markers for consistency with Hadoop FS\n     * </ul>\n     *\n     * <p>If explicit directory markers are needed, consider using a custom implementation.\n     *\n     * @return always returns true (S3 doesn't require explicit directory creation)","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-filesystems/flink-s3-fs-native/src/main/java/org/apache/flink/fs/s3native/NativeS3FileSystem.java#L387-L423","documentation":"Wraps an AWS SDK S3Exception raised while deleting an object (or while listing during recursive delete) in IOException('Failed to delete: <path>') with the original exception as cause. The S3 status code and error message in the cause explain the actual failure (403 AccessDenied, 404 NoSuchKey, 500s, etc.).","triggerScenarios":"s3Client.deleteObject fails due to missing s3:DeleteObject permissions, object locked (Object Lock / retention), bucket owner enforcement, or transient S3 5xx errors; also fired from the recursive branch for any child delete failure.","commonSituations":"IAM policies grant read but not delete; S3 Object Lock or legal hold prevents deletion; deleting objects written by a different AWS account without proper ACLs/ownership; intermittent S3 errors under load.","solutions":["Read the cause's status code: 403 -> grant s3:DeleteObject on the bucket/prefix; 500/503 -> retry with backoff.","For Object Lock-protected objects, skip deletion or use compliant retention handling; they cannot be deleted.","Retry the whole delete(path, true) — it is idempotent since already-deleted children simply no longer exist."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    s3Fs.delete(path, true);\n} catch (IOException e) {\n    if (e.getCause() instanceof S3Exception) {\n        int code = ((S3Exception) e.getCause()).statusCode();\n        if (code == 403) {\n            // fix IAM s3:DeleteObject permission, then retry\n        } else if (code >= 500) {\n            // transient S3 failure: retry delete with backoff (idempotent)\n        } else {\n            throw e;\n        }\n    } else {\n        throw e;\n    }\n}","preventionTips":["Grant s3:DeleteObject on output buckets in the execution role.","Check for Object Lock / retention before expecting deletes to succeed.","Remember recursive delete is idempotent — safe to retry whole-tree."],"tags":["s3","delete","permissions","aws-sdk"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}