apache/seatunnel · error · IOException

Failed to close Neo4j sink writer.

Error message

Failed to close Neo4j sink writer.

What it means

Neo4jSinkWriter.close() tears down session and driver resources and collects any Throwable; rethrowCloseFailure() rethrows IOExceptions and RuntimeExceptions as-is, but for any other throwable type (e.g. checked exceptions or driver internals not matching those classes) it wraps it in an IOException with this message. It signals that closing the Neo4j sink writer did not complete cleanly.

Source

Thrown at seatunnel-connectors-v2/connector-neo4j/src/main/java/org/apache/seatunnel/connectors/seatunnel/neo4j/sink/Neo4jSinkWriter.java:185

        }
    }

    private Throwable appendSuppressed(Throwable existingFailure, Throwable newFailure) {
        if (existingFailure == null) {
            return newFailure;
        }
        existingFailure.addSuppressed(newFailure);
        return existingFailure;
    }

    private void rethrowCloseFailure(Throwable throwable) throws IOException {
        if (throwable instanceof IOException) {
            throw (IOException) throwable;
        }
        if (throwable instanceof RuntimeException) {
            throw (RuntimeException) throwable;
        }
        throw new IOException("Failed to close Neo4j sink writer.", throwable);
    }

    private void flushWriteBuffer() {
        if (!writeBuffer.isEmpty()) {
            Query query = batchQuery();
            writeByQuery(query);
            writeBuffer.clear();
        }
    }
}

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Fix the underlying close/flush exception shown as the cause of the IOException
  2. Ensure buffers are flushed via prepareCommit before close so close() has nothing pending
  3. Check Neo4j connectivity at job teardown; retry the job if the failure was transient

Example fix

// before
// relying on close() to flush remaining rows
// after
writer.prepareCommit(); // flush buffer explicitly before close
writer.close();
Defensive patterns

Strategy: try-catch

Try / catch

try { writer.close(); } catch (IOException e) { if (e.getMessage().contains("Failed to close Neo4j sink writer")) { log.error("neo4j close failed", e.getCause()); } throw e; }

Prevention

When it happens

Trigger: close() failing while flushing a non-empty writeBuffer (flushWriteBuffer -> batchQuery/writeByQuery throwing) or while closing the Neo4j session/driver with a non-IOException, non-RuntimeException throwable.

Common situations: Flush during close hitting a Neo4j outage; driver internal errors on close; leftover buffered rows after a failed checkpoint being flushed at teardown.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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