t8y2/dbx · error · IllegalStateException

Connection is not valid

Error message

Connection is not valid

What it means

The validate-connection JSON-RPC method throws IllegalStateException('Connection is not valid') when, after acquiring the agent's connection, conn.isValid(2) (or the JDBC agent's validity check) reports the connection unusable. isValid calls are wrapped so any exception or AbstractMethodError simply leaves valid=false, triggering this error.

Source

Thrown at agents/common/src/main/java/com/dbx/agent/JsonRpcServer.java:182

            if (!Boolean.TRUE.equals(result.get("ok"))) {
                Object error = result.get("error");
                throw new RuntimeException(error == null ? "Connection failed" : String.valueOf(error));
            }
            return result;
        }
        if (AgentProtocol.METHOD_VALIDATE_CONNECTION.equals(method)) {
            Connection conn = agent.getConnection();
            boolean valid = false;
            if (conn != null) {
                try {
                    valid = agent instanceof AbstractJdbcAgent jdbcAgent
                        ? jdbcAgent.isConnectionValid(conn, 2)
                        : !conn.isClosed() && conn.isValid(2);
                } catch (Exception | AbstractMethodError ignored) {
                }
            }
            if (!valid) {
                throw new IllegalStateException("Connection is not valid");
            }
            return Collections.singletonMap("ok", true);
        }
        ensureLiveConnection(method);
        if (AgentProtocol.METHOD_CONNECTION_INFO.equals(method)) {
            Map<String, Object> result = new LinkedHashMap<>();
            result.put("identifierQuote", agent.getIdentifierQuote());
            Map<String, String> databaseInfo = agent.getDatabaseInfo();
            if (databaseInfo != null && !databaseInfo.isEmpty()) {
                result.put("databaseInfo", databaseInfo);
            }
            return result;
        }
        if (AgentProtocol.METHOD_LIST_DATABASES.equals(method)) {
            return agent.listDatabases();
        }
        if (AgentProtocol.METHOD_LIST_SCHEMAS.equals(method)) {
            switchCatalog(params);

View on GitHub (pinned to c0390bff16)

Solutions

  1. Call connect first (or reconnect) to establish a fresh connection, then validate
  2. Enable a connection pool/keepalive or validation query to avoid stale connections
  3. Upgrade the JDBC driver if isValid throws or is unsupported (AbstractMethodError path)
  4. Handle the error client-side by reconnecting and retrying validation

Example fix

// before
boolean ok = rpc.call("validateConnection");
// after
boolean ok;
try {
    ok = rpc.call("validateConnection");
} catch (IllegalStateException e) {
    rpc.call("connect", connectParams);
    ok = rpc.call("validateConnection");
}
Defensive patterns

Strategy: retry

Validate before calling

// ensure a connection exists before validating
Map<String,Object> ok = rpc.call("testConnection", connectParams); // must return ok=true first

Type guard

boolean sessionConnected(Map<String,Object> state) { return Boolean.TRUE.equals(state.get("ok")) && Boolean.TRUE.equals(state.get("connected")); }

Try / catch

boolean validateWithRetry() {
    for (int i = 0; i < 2; i++) {
        try { return rpc.call("validateConnection"); }
        catch (IllegalStateException e) { rpc.call("connect", connectParams); }
    }
    return false;
}

Prevention

When it happens

Trigger: Calling METHOD_VALIDATE_CONNECTION while the connection is closed, dropped by the server, timed out, or while no connection has ever been established; also when a driver throws from isValid (older drivers may not implement it).

Common situations: Database restarted or idle-connection killed between calls; network interruption; driver lacking isValid support; calling validate before connect.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/f15e636f445bcd64. Report an issue: GitHub.