apache/seatunnel · warning

Failed to finish the JDBC source read transaction. Closing…

Error message

Failed to finish the JDBC source read transaction. Closing the connection to avoid leaving or reusing an idle transaction.

What it means

JdbcInputFormat.finishReadTransaction(Connection) restores the connection's auto-commit/transaction state after a read. If that fails with SQLException, it logs this warning and discards (closes) the connection entirely, since an idle/unknown transaction left open could hold locks or block cleanup. The failure is contained to the closing path; the read result is unaffected.

Solutions

  1. No user action needed for correctness — the connection is safely closed; check the embedded SQLException for the root cause.
  2. Tune server/driver timeouts so the connection is alive at close (keepalive, wait_timeout).
  3. If recurring, enable auto-commit for read-only jobs to avoid transaction-state restoration.
  4. Upgrade the driver if it mishandles auto-commit transitions.

Example fix

// before (connection config in job)
option("auto_commit", "false")
// after (read-only source, avoid manual transaction)
option("auto_commit", "true")
Defensive patterns

Strategy: try-catch

Validate before calling

// Check connection liveness before cleanup
if (conn.isClosed()) { LOG.warn("Connection already dead at cleanup"); return; }

Try / catch

try {
    finishReadTransaction(conn);
} catch (SQLException e) {
    // internally logged and connection discarded; safe to ignore at job close
}

Prevention

When it happens

Trigger: close()/finishReadTransaction() when setAutoCommit/commit/rollback throws SQLException — connection already dead, driver rejects the transaction-state change, or network is down at job teardown.

Common situations: Non-auto-commit reads where the server terminated the connection before cleanup; driver bugs resetting auto-commit; jobs finishing after long idle periods that exceeded server timeouts.

Related errors


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

Appendix: source

Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcInputFormat.java:209

                chunkSplitter.close();
            }
            return connection;
        } catch (SQLException e) {
            LOG.warn(
                    "Failed to get the JDBC source connection from the current statement. "
                            + "Closing the cached connection to avoid reusing an unknown "
                            + "transaction.",
                    e);
            chunkSplitter.close();
            return null;
        }
    }

    private void finishReadTransaction(Connection connection) {
        try {
            finishReadTransaction(connection, configuredAutoCommit);
        } catch (SQLException e) {
            LOG.warn(
                    "Failed to finish the JDBC source read transaction. "
                            + "Closing the connection to avoid leaving or reusing an idle "
                            + "transaction.",
                    e);
            discardConnection(connection, e);
        }
    }

    private void discardConnection(Connection connection, SQLException cleanupException) {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException closeException) {
            cleanupException.addSuppressed(closeException);
            LOG.warn(
                    "Failed to close the JDBC source connection after transaction cleanup failed.",
                    cleanupException);

View on GitHub (pinned to cf67b549a7)