{"record":{"id":"0e84af644e08bee0","repo":"apache/seatunnel","slug":"failed-to-close-the-jdbc-source-connection-after-t","errorCode":null,"errorMessage":"Failed to close the JDBC source connection after transaction cleanup failed.","messagePattern":"Failed to close the JDBC source connection after transaction cleanup failed\\.","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":225,"sourceCode":"            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);\n        } finally {\n            // Clear the provider's cached reference and retry close for drivers whose first close\n            // attempt failed.\n            chunkSplitter.close();\n        }\n    }\n\n    static void finishReadTransaction(Connection connection, boolean configuredAutoCommit)\n            throws SQLException {\n        if (connection == null || connection.isClosed()) {\n            return;\n        }\n\n        boolean currentAutoCommit = connection.getAutoCommit();\n        if (!currentAutoCommit) {\n            // JDBC source reads do not have changes to commit. Rollback ends the server-side cursor","sourceCodeStart":207,"sourceCodeEnd":243,"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#L207-L243","documentation":"JdbcInputFormat.discardConnection() closes a connection after transaction cleanup already failed. If connection.close() itself throws, the close exception is attached as suppressed to the original cleanup exception and this warning logs both, then the finally block clears the provider's cached reference and retries close via chunkSplitter. It indicates the JDBC connection could not be cleanly released.","triggerScenarios":"finishReadTransaction() -> discardConnection() when connection.close() throws SQLException — broken socket at close, driver that throws instead of swallowing close errors, or already-aborted connection.","commonSituations":"Server or network gone before job teardown; buggy drivers whose close() throws on dead sockets; resource warnings at job shutdown stacking with earlier transaction errors.","solutions":["Inspect the suppressed exception and root cause; typically no action is required since the connection is discarded anyway.","Fix the root connectivity issue (network, firewall idle resets, server timeouts) that killed the connection earlier.","Upgrade the JDBC driver if close() throws spuriously on dead connections.","Ensure the finalizer/provider retry (chunkSplitter.close()) releases the underlying resource; check for connection leaks in the driver's pool."],"exampleFix":"// before\nconnection.close();\n// after\ntry {\n    if (connection != null && !connection.isClosed()) {\n        connection.close();\n    }\n} catch (SQLException e) {\n    LOG.warn(\"Discarding un-closable JDBC connection\", e);\n}","handlingStrategy":"try-catch","validationCode":"if (conn != null && !conn.isClosed()) {\n    // safe to attempt close\n}","typeGuard":null,"tryCatchPattern":"try {\n    connection.close();\n} catch (SQLException closeEx) {\n    // treat as discarded; ensure pool/finalizer reclaims the resource\n    LOG.debug(\"Connection close failed, discarded\", closeEx);\n}","preventionTips":["Fix root connectivity issues (timeouts, firewalls) so close() succeeds","Upgrade drivers whose close() throws on dead sockets","Watch for connection leaks: rely on the provider's cached-reference cleanup and verify pool metrics"],"tags":["jdbc","connection","close","resource-leak","cleanup"],"backgroundTag":"connection-closed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}