t8y2/dbx · error · IllegalStateException

Not connected. Call connect first.

Error message

Not connected. Call connect first.

What it means

requireAdmin() is the gate for every Kafka admin operation (topic metadata, configs, consumer groups, etc.). It throws IllegalStateException when adminClient is null, i.e. the agent has not established a connection via connect(), which is the only place AdminClient is created.

Source

Thrown at agents/drivers/kafka/src/main/java/com/dbx/agent/kafka/KafkaAgent.java:2635

    private static List<Throwable> causeChain(Throwable error) {
        List<Throwable> chain = new ArrayList<>();
        Set<Throwable> seen = Collections.newSetFromMap(new IdentityHashMap<>());
        Throwable current = error;
        for (int depth = 0; current != null && depth < 32 && seen.add(current); depth++) {
            chain.add(current);
            Throwable next = current.getCause();
            if (next == current) {
                break;
            }
            current = next;
        }
        return chain;
    }

    private static AdminClient requireAdmin() {
        if (adminClient == null) {
            throw new IllegalStateException("Not connected. Call connect first.");
        }
        return adminClient;
    }

    private static JsonObject connectionObject(JsonObject params) {
        JsonElement connection = params.get("connection");
        return connection != null && connection.isJsonObject()
            ? connection.getAsJsonObject() : params;
    }

    private static int requestTimeout(JsonObject params) {
        return intOrDefault(params, "timeout_ms", DEFAULT_REQUEST_TIMEOUT_MS);
    }

    private static Map<String, Object> nodeToMap(Node node) {
        Map<String, Object> m = new LinkedHashMap<>();
        m.put("id", node.id());
        m.put("host", node.host());

View on GitHub (pinned to c0390bff16)

Solutions

  1. Call the kafka connect tool first and verify it succeeded.
  2. Fix connect failures (bootstrap servers, security protocol, SASL/TLS credentials) so adminClient gets initialized.
  3. Reconnect after any disconnect/close before issuing admin calls.
  4. Sequence your calls: connect -> admin operations -> disconnect.

Example fix

// before
agent.call("kafka.list_topics", {})
// after
agent.call("kafka.connect", {"bootstrap_servers": "broker:9092"})
agent.call("kafka.list_topics", {})
Defensive patterns

Strategy: try-catch

Validate before calling

// call connect and confirm success before admin calls
agent.call("kafka.connect", cfg);
// only then
agent.call("kafka.list_topics", {});

Try / catch

try {
    agent.adminOperation(params);
} catch (IllegalStateException e) {
    if (e.getMessage().contains("Not connected")) {
        agent.connect(cfg);
        agent.adminOperation(params); // retry once after connect
    } else { throw e; }
}

Prevention

When it happens

Trigger: Any admin tool call (list topics, describe cluster, consumer group ops) before connect() completes or after disconnect() nulls adminClient.

Common situations: Running an admin query at agent startup before connect finished; connect failed due to unreachable brokers/auth so adminClient was never set; the connection was closed between operations.

Related errors


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