{"record":{"id":"a9c4ad03848cd676","repo":"apache/seatunnel","slug":"jdbc-connection-close-failed-a9c4ad","errorCode":null,"errorMessage":"JDBC connection close failed.","messagePattern":"JDBC connection close 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/connection/SimpleJdbcConnectionProvider.java","lineNumber":132,"sourceCode":"            // caller expectation.\n            throw new JdbcConnectorException(\n                    JdbcConnectorErrorCode.NO_SUITABLE_DRIVER,\n                    \"No suitable driver found for the configured JDBC URL\");\n        }\n\n        connection.setAutoCommit(jdbcConfig.isAutoCommit());\n\n        return connection;\n    }\n\n    @Override\n    public void closeConnection() {\n        try {\n            if (isConnectionValid()) {\n                connection.close();\n            }\n        } catch (SQLException e) {\n            LOG.warn(\"JDBC connection close failed.\", e);\n        } finally {\n            connection = null;\n        }\n    }\n\n    @Override\n    public Connection reestablishConnection() throws SQLException, ClassNotFoundException {\n        closeConnection();\n        return getOrEstablishConnection();\n    }\n\n    public JdbcConnectionConfig getJdbcConfig() {\n        return jdbcConfig;\n    }\n\n    public void setConnection(Connection connection) {\n        this.connection = connection;\n    }","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/connection/SimpleJdbcConnectionProvider.java#L114-L150","documentation":"SimpleJdbcConnectionProvider.closeConnection() validates then closes the single managed Connection; SQLException on close is logged as a warning and swallowed, and the connection field is always nulled in a finally block. This is deliberate best-effort cleanup: the provider never fails the task on close errors.","triggerScenarios":"reestablishConnection() -> closeConnection() with a stale/broken connection; isConnectionValid() passes but connection.close() still throws (racy network failure, driver bug).","commonSituations":"Connection dropped by DB or intermediate LB between validation and close; drivers like older MySQL throwing on close of half-closed sockets; repeated during reconnection storms.","solutions":["Fix the underlying disconnect cause (timeouts, LB idle limits, DB max_connections)","Set TCP keepalive / socketTimeout in the JDBC URL so dead sockets fail fast","Upgrade the JDBC driver if close of dead connections reliably throws","Benign if it appears during reconnection and the new connection succeeds"],"exampleFix":"// before\njdbc:mysql://host:3306/db\n// after\njdbc:mysql://host:3306/db?socketTimeout=300000&connectTimeout=60000&tcpKeepAlive=true","handlingStrategy":"try-catch","validationCode":"// pre-check before reestablish\nif (connection != null && connection.isClosed()) {\n    connection = null; // skip close, avoid SQLException path\n}","typeGuard":null,"tryCatchPattern":"// exception is swallowed internally (logged + connection nulled).\n// For your own equivalent code:\ntry { if (conn != null) conn.close(); } catch (SQLException e) { LOG.warn(\"close failed\", e); } finally { conn = null; }","preventionTips":["Set tcpKeepAlive and socket timeouts in JDBC URL","Check LB/proxy idle timeout vs job duration","Treat as benign during reconnection if the new connection succeeds"],"tags":["jdbc","connection","cleanup","warning"],"backgroundTag":"connection-refused","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"}