apache/seatunnel · error · JdbcConnectorException

WRITER_OPERATION_FAILED

WRITER_OPERATION_FAILED

Error message

unable to close JDBC sink write

What it means

On close(), JdbcSinkWriter tries to commit any still-open transaction (when autoCommit is false) before releasing resources. If obtaining the connection or committing throws SQLException, it throws JdbcConnectorException with code WRITER_OPERATION_FAILED; outputFormat.close() still runs in the finally block. This indicates pending uncommitted data may be lost or the connection is already broken.

Source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/JdbcSinkWriter.java:363

                        throwAsIoException(e);
                    }
                    handleRowLevelBatchFailure(RowErrorPhase.CLOSE, null, batchRows, e);
                } finally {
                    outputFormat.close();
                }
            }
            return;
        }

        tryOpen();
        outputFormat.flush();
        try {
            Connection connection = connectionProvider.getConnection();
            if (!connection.getAutoCommit()) {
                connection.commit();
            }
        } catch (SQLException e) {
            throw new JdbcConnectorException(
                    CommonErrorCodeDeprecated.WRITER_OPERATION_FAILED,
                    "unable to close JDBC sink write",
                    e);
        } finally {
            outputFormat.close();
        }
    }

    private void reportAndClearPendingRowsIfCommitted(boolean autoFlushed) throws IOException {
        if (pendingRows == null) {
            return;
        }
        if (autoFlushed) {
            if (markSuccessfulAutoFlushBoundaryIfNeeded()) {
                reportWriteSuccess(pendingRows);
                pendingRows.clear();
            }
        }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Inspect the SQLException cause for connection-closed/session-killed errors and fix underlying timeout/network settings.
  2. Enable connection pool validation queries and sensible idle timeouts so dead connections are evicted.
  3. Rerun the job; data committed at earlier checkpoints is safe, uncommitted tail data must be re-read by the source.
  4. If using XA/exactly-once, ensure recover transactions are cleaned up on the database.
Defensive patterns

Strategy: retry

Validate before calling

// before close-sensitive work: check connection
if (connection.isClosed()) { log.warn("connection already closed"); }

Try / catch

try {
  writer.close();
} catch (JdbcConnectorException e) {
  if (e.getSeatunnelCode() == CommonErrorCodeDeprecated.WRITER_OPERATION_FAILED) {
    // cause is SQLException: treat as connection loss, rerun job from checkpoint
  }
}

Prevention

When it happens

Trigger: Writer close at job end or on failure recovery: connectionProvider.getConnection() fails (pool exhausted, connection closed) or connection.commit() throws because the session was killed, network dropped, or the transaction was already rolled back server-side.

Common situations: Long-running jobs whose DB session timed out before close; DBA killed a long transaction; connection pool stale connections; abrupt network failures during job shutdown.

Related errors


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