jd-opensource/joyagent-jdgenie · error · JdbcBizException

重试获取数据库链接失败

Error message

重试获取数据库链接失败

What it means

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.

Solutions

  1. Restore database connectivity (check host, port, credentials, pool exhaustion).
  2. Avoid interrupting the thread running the query; check executor shutdown logic.
  3. Increase maxRetryTime or the 300ms sleep if the DB recovers slowly.
  4. Inspect the wrapped InterruptedException to find who interrupted the thread.
  5. Check HikariCP pool settings — pool exhaustion can make every attempt time out.

Example fix

// before
executor.shutdownNow(); // interrupts in-flight getConnection, throws JdbcBizException
// after
executor.shutdown();
executor.awaitTermination(30, TimeUnit.SECONDS); // let retries finish gracefully
Defensive patterns

Strategy: retry

Validate before calling

// Java: cheap connectivity probe before running queries
boolean reachable = false;
try (Connection c = DriverManager.getConnection(url, user, pass)) { reachable = true; }
catch (SQLException e) { /* schedule retry / alert */ }

Try / catch

try {
    wrapper.getConnection();
} catch (JdbcBizException e) {
    if (e.getCause() instanceof InterruptedException) {
        Thread.currentThread().interrupt(); // restore interrupt flag
    }
    // treat as cancellation or exhausted retries
}

Prevention

When it happens

Trigger: 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).

Common situations: Application shutdown mid-request, task cancelled by an executor with interrupt, or DB outage longer than the total retry window (maxRetryTime × 300ms).

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08). Data as JSON: /api/errors/fd3a4046da6dec30. Report an issue: GitHub.

Appendix: source

Thrown at genie-backend/src/main/java/com/jd/genie/data/jdbc/connection/ConnectionWrapper.java:49

    public Statement createStreamStatement(Connection connection, Integer fetchSize) throws SQLException {
        return jdbcDialect.createStreamStatement(connection, fetchSize);
    }

    public Connection getConnection() {
        int maxRetryTime = jdbcConnectionConfig.getMaxRetryTimes();
        int i = 0;
        Connection connection = null;
        while (i < maxRetryTime) {
            try {
                connection = datasourceWrapper.getDataSource().getConnection();
                log.info("获取数据库链接成功 poolId:{}", jdbcConnectionConfig.getKey());
                break;
            } catch (SQLException e) {
                if (i < maxRetryTime - 1) {
                    try {
                        Thread.sleep(300);
                    } catch (InterruptedException ie) {
                        throw new JdbcBizException(
                                "重试获取数据库链接失败",
                                ie);
                    }
                    log.warn("获取数据库链接失败, 重试次数 {}", i + 1);
                } else {
                    log.error("重试{}次后未后成功", i + 1);
                    throw new JdbcBizException(e);
                }
            }
            i++;
        }
        return connection;
    }
}

View on GitHub (pinned to 2417e0b8b6)