apache/seatunnel · info

Trace file already closed: {}

Error message

Trace file already closed: {}

What it means

TraceFileWriter.close() logs this warning when the file channel is already closed (ClosedChannelException or 'Stream closed'). This can happen when close is invoked twice or the channel was closed elsewhere; the writer treats it as benign and returns instead of rethrowing.

Source

Thrown at seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/event/TraceFileWriter.java:145

        return date;
    }

    @Override
    public void close() throws IOException {
        if (!closed.compareAndSet(false, true)) {
            return;
        }
        try {
            writer.close();
            log.info(
                    "Closed trace file: {} (events={}, size={} bytes)",
                    filePath,
                    eventCount.get(),
                    fileSize.get());
        } catch (IOException e) {
            if (e instanceof ClosedChannelException
                    || (e.getMessage() != null && e.getMessage().contains("Stream closed"))) {
                log.warn("Trace file already closed: {}", filePath);
                return;
            }
            log.error("Failed to close trace file: " + filePath, e);
            throw e;
        }
    }
}

View on GitHub (pinned to cf67b549a7)

Solutions

  1. None required — this is intentionally handled as a benign no-op.
  2. If frequent, audit close() call sites to ensure single-owner closing of the writer under writerLock.

Example fix

null
Defensive patterns

Strategy: try-catch

Try / catch

try { writer.close(); } catch (IOException e) { if (e instanceof ClosedChannelException) { /* already closed, ignore */ } else { throw e; } }

Prevention

When it happens

Trigger: close() is called on a TraceFileWriter whose channel was already closed — e.g. double close during handler shutdown, or the writer was closed concurrently by another shutdown path.

Common situations: Overlapping shutdown paths (scheduler close + handler close) both attempting to close the same trace file; roll-and-close logic racing at rotation time.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


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