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
- Call the kafka connect tool first and verify it succeeded.
- Fix connect failures (bootstrap servers, security protocol, SASL/TLS credentials) so adminClient gets initialized.
- Reconnect after any disconnect/close before issuing admin calls.
- 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
- Initialize the connection as the first step of every session.
- Investigate connect failures rather than proceeding with subsequent calls.
- Re-issue connect after any disconnect/close event.
- Serialize admin calls after connect completes; avoid concurrent disconnect/send races.
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
- Kafka topic does not exist: " + name
- Kafka Agent is not connected
- Producer is not initialized. Call connect first.
- RocketMQ agent is not connected
- JDBC pool registry must be attached before connecting
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/65bad6a1c7326e4d.
Report an issue: GitHub.