apache/seatunnel · warning

Failed to delete log file

Error message

Failed to delete log file: {}

What it means

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.

Solutions

  1. Check filesystem permissions on the log file and parent directory and grant delete rights to the SeaTunnel process user.
  2. Ensure the job has fully finished before cleaning; retry the cleanup after the job stops.
  3. Verify the configured log storage path points to a writable, local (non-locked) filesystem.
  4. Manually remove the offending file and re-run cleanup if automated cleanup cannot.

Example fix

// before: read-only mount prevents delete
log_path: /mnt/ro-logs/seatunnel/logs
// after
log_path: /var/log/seatunnel/logs // writable by seatunnel user
Defensive patterns

Strategy: validation

Validate before calling

// before cleaning, check deletability
File f = Paths.get(logPath).toFile();
if (!f.exists() || !f.canWrite()) {
    log.warn("cannot delete log {} (missing/unwritable)", logPath);
}

Type guard

boolean isDeletable(Path p) {
    File f = p.toFile();
    return f.exists() && f.isFile() && f.getParentFile().canWrite();
}

Try / catch

try {
    Files.delete(Paths.get(logPath));
} catch (IOException e) {
    log.warn("log cleanup failed for {}", logPath, e);
    retryLater(e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/cc6b91288403bbab. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/telemetry/log/TaskLogManagerService.java:65

            log.debug(
                    "The corresponding log file path is not properly configured, please check the log configuration file.",
                    e);
        }
    }

    /** Removes local log files whose names still include the target job id. */
    public void clean(long jobId) {
        if (path == null || jobId <= 0) {
            return;
        }
        String[] logFiles = getLogFiles(jobId, path);
        for (String logFile : logFiles) {
            String logPath = path + "/" + logFile;
            log.info("Cleaning logs for jobId: {} , path : {}", jobId, logPath);
            try {
                Files.delete(Paths.get(logPath));
            } catch (IOException e) {
                log.warn("Failed to delete log file: {}", logPath, e);
            }
        }
    }

    private String[] getLogFiles(long jobId, String path) {
        File logDir = new File(path);
        if (!logDir.exists() || !logDir.isDirectory()) {
            log.warn(
                    "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.",
                    path);
            return new String[0];
        }

        return logDir.list((dir, name) -> name.contains(String.valueOf(jobId)));
    }
}

View on GitHub (pinned to cf67b549a7)