{"record":{"id":"fd3a4046da6dec30","repo":"jd-opensource/joyagent-jdgenie","slug":"error-fd3a40","errorCode":null,"errorMessage":"重试获取数据库链接失败","messagePattern":"重试获取数据库链接失败","errorType":"exception","errorClass":"JdbcBizException","httpStatus":null,"severity":"error","filePath":"genie-backend/src/main/java/com/jd/genie/data/jdbc/connection/ConnectionWrapper.java","lineNumber":49,"sourceCode":"    public Statement createStreamStatement(Connection connection, Integer fetchSize) throws SQLException {\n        return jdbcDialect.createStreamStatement(connection, fetchSize);\n    }\n\n    public Connection getConnection() {\n        int maxRetryTime = jdbcConnectionConfig.getMaxRetryTimes();\n        int i = 0;\n        Connection connection = null;\n        while (i < maxRetryTime) {\n            try {\n                connection = datasourceWrapper.getDataSource().getConnection();\n                log.info(\"获取数据库链接成功 poolId:{}\", jdbcConnectionConfig.getKey());\n                break;\n            } catch (SQLException e) {\n                if (i < maxRetryTime - 1) {\n                    try {\n                        Thread.sleep(300);\n                    } catch (InterruptedException ie) {\n                        throw new JdbcBizException(\n                                \"重试获取数据库链接失败\",\n                                ie);\n                    }\n                    log.warn(\"获取数据库链接失败, 重试次数 {}\", i + 1);\n                } else {\n                    log.error(\"重试{}次后未后成功\", i + 1);\n                    throw new JdbcBizException(e);\n                }\n            }\n            i++;\n        }\n        return connection;\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":64,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-backend/src/main/java/com/jd/genie/data/jdbc/connection/ConnectionWrapper.java#L31-L64","documentation":"ConnectionWrapper.getConnection retries acquiring a JDBC connection up to maxRetryTime. If the thread is interrupted while sleeping between retries, it throws JdbcBizException '重试获取数据库链接失败' wrapping the InterruptedException. It also marks the retry loop as failed when all attempts are exhausted.","triggerScenarios":"Called by queryTables, queryColumns, getTableColumnsOfSql and queryData; occurs when the database is unreachable for all retries and the waiting thread is interrupted (shutdown, executor cancel, timeout).","commonSituations":"Application shutdown mid-request, task cancelled by an executor with interrupt, or DB outage longer than the total retry window (maxRetryTime × 300ms).","solutions":["Restore database connectivity (check host, port, credentials, pool exhaustion).","Avoid interrupting the thread running the query; check executor shutdown logic.","Increase maxRetryTime or the 300ms sleep if the DB recovers slowly.","Inspect the wrapped InterruptedException to find who interrupted the thread.","Check HikariCP pool settings — pool exhaustion can make every attempt time out."],"exampleFix":"// before\nexecutor.shutdownNow(); // interrupts in-flight getConnection, throws JdbcBizException\n// after\nexecutor.shutdown();\nexecutor.awaitTermination(30, TimeUnit.SECONDS); // let retries finish gracefully","handlingStrategy":"retry","validationCode":"// Java: cheap connectivity probe before running queries\nboolean reachable = false;\ntry (Connection c = DriverManager.getConnection(url, user, pass)) { reachable = true; }\ncatch (SQLException e) { /* schedule retry / alert */ }","typeGuard":null,"tryCatchPattern":"try {\n    wrapper.getConnection();\n} catch (JdbcBizException e) {\n    if (e.getCause() instanceof InterruptedException) {\n        Thread.currentThread().interrupt(); // restore interrupt flag\n    }\n    // treat as cancellation or exhausted retries\n}","preventionTips":["Avoid shutdownNow()/interrupt on threads doing JDBC work.","Size maxRetryTime to exceed expected transient DB outages.","Monitor connection-pool exhaustion in HikariCP metrics.","Tune the 300ms backoff for slow-recovering databases."],"tags":["jdbc","connection","retry","interrupted"],"backgroundTag":"request-timeout","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}