{"record":{"id":"64f36a4dabd10ce0","repo":"apache/seatunnel","slug":"unable-to-close-xa-connection","errorCode":null,"errorMessage":"unable to close XA connection","messagePattern":"unable to close XA connection","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/xa/XaFacadeImplAutoLoad.java","lineNumber":138,"sourceCode":"\n    @Override\n    public void close() throws SQLException {\n        if (connection != null) {\n            connection.close(); // close connection - likely a wrapper\n            connection = null;\n        }\n        try {\n            xaConnection.close(); // close likely a pooled AND the underlying connection\n        } catch (SQLException e) {\n            // Some databases (e.g. MySQL) rollback changes on normal client disconnect which\n            // causes an exception if an XA transaction was prepared. Note that resources are\n            // still released in case of an error. Pinning MySQL connections doesn't help as\n            // SuspendableXAConnection has the same close() logic.\n            // Other DBs don't rollback, e.g. for PgSql the previous connection.close() call\n            // disassociates the connection (and that call works because it has a check for XA)\n            // and rollback() is not called.\n            // In either case, not closing the XA connection here leads to the resource leak.\n            LOG.warn(\"unable to close XA connection\", e);\n        }\n        xaResource = null;\n    }\n\n    @Override\n    public Connection getConnection() {\n        checkNotNull(connection);\n        return connection;\n    }\n\n    @Override\n    public boolean isConnectionValid() throws SQLException {\n        return isOpen() && connection.isValid(connection.getNetworkTimeout());\n    }\n\n    @Override\n    public Connection getOrEstablishConnection() throws SQLException {\n        if (!isOpen()) {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/xa/XaFacadeImplAutoLoad.java#L120-L156","documentation":"A WARN log in XaFacadeImplAutoLoad.close() when closing the underlying XA connection throws a SQLException. The resource is still discarded (xaResource nulled) even though the close failed; this is logged to flag a potential connection leak on the database side while not failing the job. Recovery: the connection object remains referenced by the JDBC driver until GC; some DBs may leak XA resources.","triggerScenarios":"close() attempts connection.close() on the physical XA connection and the driver throws SQLException — e.g. the network is already broken, the DB killed the session, or the driver already closed it (MySQL SuspendableXAConnection quirks).","commonSituations":"Job shutdown/recovery while the database connection is stale after long checkpoint intervals; MySQL connections pinned by XA; firewalled/idle connections dropped mid-run.","solutions":["Verify network/firewall idle timeouts exceed checkpoint interval; enable TCP keepalive on the DB connection","Check DB-side session limits and stale-connection cleanup (e.g. wait_timeout in MySQL)","If leaks accumulate, restart the task or recycle the DataSource; this warning is otherwise safe to ignore at shutdown","Upgrade the JDBC driver if a known close-after-XA bug applies"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before shutdown-sensitive jobs, verify DB connectivity\ntry (Connection c = dataSource.getConnection()) { /* healthy */ }","typeGuard":null,"tryCatchPattern":"try {\n    xaFacade.close();\n} catch (Exception e) {\n    // logged as 'unable to close XA connection'; non-fatal at shutdown\n    LOG.warn(\"XA close failed, relying on DB-side cleanup/GC\", e);\n}","preventionTips":["Set DB idle/network timeouts (wait_timeout, firewall idle) longer than checkpoint interval","Enable TCP keepalive on JDBC connections","Monitor DB-side for leaked sessions and clean with session kill if they accumulate"],"tags":["jdbc","xa","connection-close","resource-leak"],"backgroundTag":"connection-refused","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}