apache/seatunnel · warning · IotdbConnectorException

IotdbConnectorErrorCode.CLOSE_CLIENT_FAILED

IotdbConnectorErrorCode.CLOSE_CLIENT_FAILED

Error message

Close IoTDB client failed.

What it means

IoTDBSinkClient.close() closes the IoTDB Session when the writer is being released; if session.close() throws IoTDBConnectionException it rethrows CLOSE_CLIENT_FAILED. Like the source-side session-close error, it signals the connection was already dead or the server rejected the close, not a logic error in close().

Source

Thrown at seatunnel-connectors-v2/connector-iotdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/iotdb/sink/IoTDBSinkClient.java:113

        tryInit();
        checkFlushException();

        batchList.add(record);
        if (sinkConfig.getBatchSize() > 0 && batchList.size() >= sinkConfig.getBatchSize()) {
            flush();
        }
    }

    public synchronized void close() throws IOException {
        flush();

        try {
            if (session != null) {
                session.close();
            }
        } catch (IoTDBConnectionException e) {
            log.error("Close IoTDB client failed.", e);
            throw new IotdbConnectorException(
                    IotdbConnectorErrorCode.CLOSE_CLIENT_FAILED, "Close IoTDB client failed.", e);
        }
    }

    synchronized void flush() throws IOException {
        checkFlushException();
        if (batchList.isEmpty()) {
            return;
        }

        BatchRecords batchRecords = new BatchRecords(batchList);
        for (int i = 0; i <= sinkConfig.getMaxRetries(); i++) {
            try {
                if (batchRecords.getTypesList().isEmpty()) {
                    session.insertRecords(
                            batchRecords.getDeviceIds(),
                            batchRecords.getTimestamps(),
                            batchRecords.getMeasurementsList(),

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Check the wrapped IoTDBConnectionException cause and IoTDB server logs for the connection state at close time
  2. Ensure flush() is called successfully before close so pending data is not lost (data loss, not close, is the real risk)
  3. Keep the connection alive for long jobs (TCP keepalive, avoid long idle periods between batches)
  4. If transient, treat as a job-level failure and rerun; verify network stability between SeaTunnel worker and IoTDB

Example fix

// before
public void close() throws IOException {
    try {
        if (session != null) {
            session.close();
        }
    } catch (IoTDBConnectionException e) {
        throw new IotdbConnectorException(IotdbConnectorErrorCode.CLOSE_CLIENT_FAILED, "Close IoTDB client failed.", e);
    }
}
// after
public void close() throws IOException {
    try {
        flush();
    } finally {
        try {
            if (session != null) {
                session.close();
            }
        } catch (IoTDBConnectionException e) {
            log.warn("Session already closed/broken: {}", e.getMessage());
            throw new IotdbConnectorException(IotdbConnectorErrorCode.CLOSE_CLIENT_FAILED, "Close IoTDB client failed.", e);
        }
    }
}
Defensive patterns

Strategy: try-catch

Type guard

boolean sessionAlive(IoTDBSinkClient client) { return client != null; }

Try / catch

try {
    sinkWriter.close();
} catch (IotdbConnectorException e) {
    if (e.getCode() == IotdbConnectorErrorCode.CLOSE_CLIENT_FAILED) {
        log.warn("IoTDB session close failed (connection likely already broken): {}", e.getCause());
    } else { throw e; }
}

Prevention

When it happens

Trigger: close() invoked at end-of-task/checkpoint while session != null and session.close() raises IoTDBConnectionException — server restarted mid-job, session timed out, network dropped, or session already closed.

Common situations: Long-running sink job whose idle TCP connection was dropped by a firewall; IoTDB DataNode restarted during the job; double-close after a prior failure path already terminated the session.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


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