{"record":{"id":"5ef7e1c7478547e2","repo":"apache/seatunnel","slug":"failed-to-finish-the-jdbc-source-read-transaction","errorCode":null,"errorMessage":"Failed to finish the JDBC source read transaction. Closing the connection to avoid leaving or reusing an idle transaction.","messagePattern":"Failed to finish the JDBC source read transaction\\. Closing the connection to avoid leaving or reusing an idle transaction\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcInputFormat.java","lineNumber":209,"sourceCode":"                chunkSplitter.close();\n            }\n            return connection;\n        } catch (SQLException e) {\n            LOG.warn(\n                    \"Failed to get the JDBC source connection from the current statement. \"\n                            + \"Closing the cached connection to avoid reusing an unknown \"\n                            + \"transaction.\",\n                    e);\n            chunkSplitter.close();\n            return null;\n        }\n    }\n\n    private void finishReadTransaction(Connection connection) {\n        try {\n            finishReadTransaction(connection, configuredAutoCommit);\n        } catch (SQLException e) {\n            LOG.warn(\n                    \"Failed to finish the JDBC source read transaction. \"\n                            + \"Closing the connection to avoid leaving or reusing an idle \"\n                            + \"transaction.\",\n                    e);\n            discardConnection(connection, e);\n        }\n    }\n\n    private void discardConnection(Connection connection, SQLException cleanupException) {\n        try {\n            if (connection != null) {\n                connection.close();\n            }\n        } catch (SQLException closeException) {\n            cleanupException.addSuppressed(closeException);\n            LOG.warn(\n                    \"Failed to close the JDBC source connection after transaction cleanup failed.\",\n                    cleanupException);","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcInputFormat.java#L191-L227","documentation":"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.","triggerScenarios":"close()/finishReadTransaction() when setAutoCommit/commit/rollback throws SQLException — connection already dead, driver rejects the transaction-state change, or network is down at job teardown.","commonSituations":"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.","solutions":["No user action needed for correctness — the connection is safely closed; check the embedded SQLException for the root cause.","Tune server/driver timeouts so the connection is alive at close (keepalive, wait_timeout).","If recurring, enable auto-commit for read-only jobs to avoid transaction-state restoration.","Upgrade the driver if it mishandles auto-commit transitions."],"exampleFix":"// before (connection config in job)\noption(\"auto_commit\", \"false\")\n// after (read-only source, avoid manual transaction)\noption(\"auto_commit\", \"true\")","handlingStrategy":"try-catch","validationCode":"// Check connection liveness before cleanup\nif (conn.isClosed()) { LOG.warn(\"Connection already dead at cleanup\"); return; }","typeGuard":null,"tryCatchPattern":"try {\n    finishReadTransaction(conn);\n} catch (SQLException e) {\n    // internally logged and connection discarded; safe to ignore at job close\n}","preventionTips":["Use auto-commit for read-only jobs to avoid transaction-state restoration","Keep connections alive (keepalive/valid timeouts) so cleanup succeeds","Review the embedded SQLException cause if the warning recurs"],"tags":["jdbc","connection","transaction","cleanup","close"],"backgroundTag":"connection-closed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}