{"record":{"id":"00d9470615c33e5a","repo":"apache/seatunnel","slug":"failed-to-get-the-jdbc-source-connection-from-the","errorCode":null,"errorMessage":"Failed to get the JDBC source connection from the current statement. Closing the cached connection to avoid reusing an unknown transaction.","messagePattern":"Failed to get the JDBC source connection from the current statement\\. Closing the cached connection to avoid reusing an unknown 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":195,"sourceCode":"        finishReadTransaction(connection);\n    }\n\n    private Connection getStatementConnection() {\n        if (statement == null) {\n            return null;\n        }\n        try {\n            Connection connection = statement.getConnection();\n            if (connection == null) {\n                LOG.warn(\n                        \"The JDBC source statement returned no connection. \"\n                                + \"Closing the cached connection to avoid reusing an unknown \"\n                                + \"transaction.\");\n                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);","sourceCodeStart":177,"sourceCodeEnd":213,"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#L177-L213","documentation":"JdbcInputFormat.getStatementConnection() calls statement.getConnection(); if the driver throws SQLException there, the format logs this warning (with the exception) and closes the cached connection through chunkSplitter, returning null so the invalid connection/transaction is never reused. It signals the JDBC source has lost access to its statement's connection.","triggerScenarios":"connection()/getStatementConnection() when statement.getConnection() throws SQLException — statement already closed, connection aborted by the driver, or driver-level communication failure.","commonSituations":"Long-running source reads hitting network timeouts or server-side connection kills (wait_timeout); drivers closing statements after errors; transactional reads across checkpoint restore where the cached connection is stale.","solutions":["Enable connection keepalive/validation and adjust server-side timeouts (e.g., MySQL wait_timeout) above job durations.","Retry the read task — SeaTunnel will recreate the connection; ensure restart strategy is configured.","Upgrade/replace the JDBC driver if it throws spuriously from getConnection().","Check prior errors in logs that closed the statement before this call."],"exampleFix":"// before\njdbc_url=jdbc:mysql://host:3306/db?useSSL=true\n// after (keepalive above idle timeout)\njdbc_url=jdbc:mysql://host:3306/db?useSSL=true&autoReconnect=true&socketTimeout=3600000&connectTimeout=60000","handlingStrategy":"retry","validationCode":"// Validate before reuse\nif (conn.isClosed() || !conn.isValid(5)) {\n    LOG.warn(\"Connection invalid before read — reopening\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Connection c = format.getStatementConnection();\n} catch (SQLException e) {\n    // logged internally; allow the source task to retry and recreate the connection\n    throw new IOException(e);\n}","preventionTips":["Raise MySQL wait_timeout / TCP idle limits above read duration","Enable connection validation and keepalive in the JDBC URL","Ensure job restart/retry strategy is enabled for transient connection loss"],"tags":["jdbc","connection","sql-exception","transaction","network"],"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"}