{"record":{"id":"cc6b91288403bbab","repo":"apache/seatunnel","slug":"failed-to-delete-log-file","errorCode":null,"errorMessage":"Failed to delete log file: {}","messagePattern":"Failed to delete log file: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/telemetry/log/TaskLogManagerService.java","lineNumber":65,"sourceCode":"            log.debug(\n                    \"The corresponding log file path is not properly configured, please check the log configuration file.\",\n                    e);\n        }\n    }\n\n    /** Removes local log files whose names still include the target job id. */\n    public void clean(long jobId) {\n        if (path == null || jobId <= 0) {\n            return;\n        }\n        String[] logFiles = getLogFiles(jobId, path);\n        for (String logFile : logFiles) {\n            String logPath = path + \"/\" + logFile;\n            log.info(\"Cleaning logs for jobId: {} , path : {}\", jobId, logPath);\n            try {\n                Files.delete(Paths.get(logPath));\n            } catch (IOException e) {\n                log.warn(\"Failed to delete log file: {}\", logPath, e);\n            }\n        }\n    }\n\n    private String[] getLogFiles(long jobId, String path) {\n        File logDir = new File(path);\n        if (!logDir.exists() || !logDir.isDirectory()) {\n            log.warn(\n                    \"Skipping deletion: Log directory '{}' either does not exist or is not a valid directory. Please verify the path and ensure the logs are being written correctly.\",\n                    path);\n            return new String[0];\n        }\n\n        return logDir.list((dir, name) -> name.contains(String.valueOf(jobId)));\n    }\n}\n","sourceCodeStart":47,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/telemetry/log/TaskLogManagerService.java#L47-L82","documentation":"TaskLogManagerService.clean iterates a job's log files and deletes each with Files.delete. If a specific log file cannot be deleted (IOException), this WARN is logged and the loop continues with remaining files. Some stale job logs may remain on disk, consuming space, but the cleaning process is not aborted.","triggerScenarios":"Files.delete(Paths.get(logPath)) throws IOException — file locked by another process, permission denied on the file or parent directory, or file disappeared between listing and delete.","commonSituations":"Log dir owned by another user or read-only mount; logs still being written by a running task while cleanup runs; NFS/Windows file locks; misconfigured telemetry log path.","solutions":["Check filesystem permissions on the log file and parent directory and grant delete rights to the SeaTunnel process user.","Ensure the job has fully finished before cleaning; retry the cleanup after the job stops.","Verify the configured log storage path points to a writable, local (non-locked) filesystem.","Manually remove the offending file and re-run cleanup if automated cleanup cannot."],"exampleFix":"// before: read-only mount prevents delete\nlog_path: /mnt/ro-logs/seatunnel/logs\n// after\nlog_path: /var/log/seatunnel/logs // writable by seatunnel user","handlingStrategy":"validation","validationCode":"// before cleaning, check deletability\nFile f = Paths.get(logPath).toFile();\nif (!f.exists() || !f.canWrite()) {\n    log.warn(\"cannot delete log {} (missing/unwritable)\", logPath);\n}","typeGuard":"boolean isDeletable(Path p) {\n    File f = p.toFile();\n    return f.exists() && f.isFile() && f.getParentFile().canWrite();\n}","tryCatchPattern":"try {\n    Files.delete(Paths.get(logPath));\n} catch (IOException e) {\n    log.warn(\"log cleanup failed for {}\", logPath, e);\n    retryLater(e);\n}","preventionTips":["Run cleanup only after the job has fully stopped.","Ensure the SeaTunnel user owns/can write the log directory on every node.","Avoid network filesystems prone to locking for job logs.","Schedule periodic re-cleanups to catch files missed earlier."],"tags":["file-deletion","io","logs","cleanup"],"backgroundTag":"file-delete-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}