{"record":{"id":"5662c2f1b165106f","repo":"apache/seatunnel","slug":"error-while-closing-databend-source-reader","errorCode":null,"errorMessage":"Error while closing Databend source reader","messagePattern":"Error while closing Databend source reader","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-databend/src/main/java/org/apache/seatunnel/connectors/seatunnel/databend/source/DatabendSourceReader.java","lineNumber":316,"sourceCode":"                        typeName);\n                return BasicType.STRING_TYPE;\n        }\n    }\n\n    @Override\n    public void close() throws IOException {\n        try {\n            if (resultSet != null) {\n                resultSet.close();\n            }\n            if (statement != null) {\n                statement.close();\n            }\n            if (connection != null) {\n                connection.close();\n            }\n        } catch (SQLException e) {\n            throw new IOException(\"Error while closing Databend source reader\", e);\n        }\n    }\n}\n","sourceCodeStart":298,"sourceCodeEnd":320,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-databend/src/main/java/org/apache/seatunnel/connectors/seatunnel/databend/source/DatabendSourceReader.java#L298-L320","documentation":"This error is thrown by DatabendSourceReader.close() when releasing the JDBC Statement or Connection fails with a SQLException during reader shutdown. The original SQLException is wrapped in an IOException so it surfaces as a source-reader close failure rather than a read failure. It usually indicates the connection was already broken or already closed by the time cleanup ran.","triggerScenarios":"Calling close() on the reader while the JDBC connection to Databend has been dropped (network cut, Databend restarted, idle timeout) so connection.close() throws; closing an already-closed connection; driver-level socket errors during statement.close().","commonSituations":"Long-running batch jobs where Databend or a LB closes idle connections; container network interruptions; job cancellation racing with connection teardown; duplicate close() calls on the same reader.","solutions":["Inspect the wrapped SQLException cause: if it reports 'connection already closed' or socket timeout, the close failure is benign and the reader was effectively cleaned up - fix the underlying connection stability instead","Enable JDBC keepalive/heartbeat and tune Datasense/proxy idle timeouts so connections survive long reads","Wrap each close() (statement, connection) in its own try-catch so one resource failing to close does not abort the other's cleanup","Verify network stability between the SeaTunnel worker and Databend (firewalls, NAT idle timeouts, Databend query timeouts)"],"exampleFix":"// before\nstatement.close();\nconnection.close();\n// after\ntry {\n    if (statement != null) statement.close();\n} catch (SQLException e) {\n    log.warn(\"Failed to close Databend statement\", e);\n}\ntry {\n    if (connection != null) connection.close();\n} catch (SQLException e) {\n    log.warn(\"Failed to close Databend connection\", e);\n}","handlingStrategy":"try-catch","validationCode":"// before closing: check connection validity\nif (connection != null && !connection.isClosed()) {\n    connection.close();\n}","typeGuard":"boolean isOpen(Connection c) { try { return c != null && !c.isClosed(); } catch (SQLException e) { return false; } }","tryCatchPattern":"try { reader.close(); } catch (IOException e) {\n    if (e.getCause() instanceof SQLException && \"08003\".equals(((SQLException) e.getCause()).getSQLState())) {\n        log.warn(\"Connection already closed; ignoring\", e);\n    } else { throw e; }\n}","preventionTips":["Always null-check and isClosed()-check JDBC resources before closing","Tune TCP/JDBC keepalive so idle connections are not dropped mid-job","Test reader close paths under job cancellation to ensure cleanup is fault-tolerant"],"tags":["jdbc","databend","resource-cleanup","io"],"backgroundTag":"database-query-failed","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"}