{"record":{"id":"f6397d7da0ae27c0","repo":"apache/seatunnel","slug":"failed-to-close-catalog","errorCode":null,"errorMessage":"Failed to close catalog","messagePattern":"Failed to close catalog","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-databend/src/main/java/org/apache/seatunnel/connectors/seatunnel/databend/source/DatabendSourceFactory.java","lineNumber":120,"sourceCode":"                        \"Failed to get table schema from catalog, will try to infer schema from query\",\n                        e);\n                TableSchema.Builder builder = TableSchema.builder();\n                TableSchema tableSchema = builder.build();\n                CatalogTable catalogTable =\n                        CatalogTable.of(\n                                TableIdentifier.of(catalogName, database, table),\n                                tableSchema,\n                                Collections.emptyMap(),\n                                Collections.emptyList(),\n                                \"\",\n                                catalogName);\n                return new DatabendSource(\n                        catalogTable, sql, url, ssl, username, password, fetchSize);\n            } finally {\n                try {\n                    catalog.close();\n                } catch (Exception e) {\n                    log.warn(\"Failed to close catalog\", e);\n                }\n            }\n        };\n    }\n\n    /** according to the options, build the SQL statement */\n    private String buildSqlStatement(ReadonlyConfig options) {\n        if (options.getOptional(DatabendSourceOptions.SQL).isPresent()) {\n            return options.get(DatabendSourceOptions.SQL);\n        }\n\n        String query = options.getOptional(DatabendOptions.QUERY).orElse(null);\n        if (query != null) {\n            return query;\n        }\n\n        String database = options.getOptional(DATABASE).orElse(null);\n        String table = options.getOptional(DatabendOptions.TABLE).orElse(null);","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-databend/src/main/java/org/apache/seatunnel/connectors/seatunnel/databend/source/DatabendSourceFactory.java#L102-L138","documentation":"In DatabendSourceFactory.createSource()'s finally block, closing the Databend catalog throws and this warning is logged. The source has already been constructed, so job execution is unaffected — this only means the catalog's underlying connection may leak until GC. It is almost always a secondary symptom of a broken JDBC connection.","triggerScenarios":"catalog.close() is called after source creation (success or failure) and the underlying connection is already dead/closed, making the driver's close() throw.","commonSituations":"Databend restarted or connection dropped during source initialization; factory error path where catalog creation half-failed; driver quirks closing an already-invalid connection.","solutions":["Treat as a symptom: fix the underlying connection failure logged earlier","Check for connection leaks/timeouts; tune JDBC connection parameters","Ensure the catalog isn't closed twice elsewhere in custom code","If warnings are noisy, safely ignore — the job result is not affected; consider upgrading the JDBC driver"],"exampleFix":"// before\n} finally {\n    try {\n        catalog.close();\n    } catch (Exception e) {\n        log.warn(\"Failed to close catalog\", e);\n    }\n}\n// after\n} finally {\n    try {\n        if (catalog != null) {\n            catalog.close();\n        }\n    } catch (Exception e) {\n        log.debug(\"Catalog close failed (likely connection already closed): {}\", e.getMessage());\n    }\n}","handlingStrategy":"try-catch","validationCode":"try (Connection c = DriverManager.getConnection(url, user, pass)) {\n    if (!c.isValid(5)) throw new IllegalStateException(\"Databend connection invalid\");\n}","typeGuard":"boolean safelyClosable(AutoCloseable catalog) {\n    return catalog != null; // close() exceptions are logged, never fatal\n}","tryCatchPattern":"try {\n    Source source = factory.createSource(context);\n} catch (Exception e) {\n    log.warn(\"createSource failed (catalog close warning may also appear)\", e);\n    // focus on the primary exception, not the close warning\n}","preventionTips":["Fix underlying connection stability so close() succeeds","Ignore this warning when a primary failure is present — it is secondary","Keep JDBC driver up to date for correct close semantics on dead connections"],"tags":["resource-cleanup","jdbc","catalog","connection"],"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-14T05:17:10.506Z"}