apache/kafka · critical · IllegalStateException

There are no nodes in the Kafka cluster

Error message

There are no nodes in the Kafka cluster

What it means

Thrown by NetworkClient.handleEmptyNodeList() when the cluster metadata contains zero nodes and either bootstrap is disabled or bootstrapping is already complete. It signals the client cannot find any broker to talk to and is not still in the initial DNS-resolution phase where an empty result would be tolerable.

Solutions

  1. Verify bootstrap.servers config points to valid, reachable broker addresses.
  2. Check network connectivity and DNS resolution for each bootstrap host.
  3. Ensure the Kafka cluster has live brokers and the client can reach at least one.
  4. If using a custom bootstrap configuration, confirm it is not prematurely marked as bootstrapped.
Defensive patterns

Strategy: validation

Validate before calling

// Before relying on leastLoadedNode, ensure metadata has nodes
if (metadata.fetch().nodes().isEmpty()) {
    throw new IllegalStateException("No nodes available; check bootstrap.servers");
}

Try / catch

try {
    client.leastLoadedNode(now);
} catch (IllegalStateException e) {
    // bootstrap/config issue: surface to operator, do not retry blindly
}

Prevention

When it happens

Trigger: leastLoadedNode() is called when metadataUpdater reports no nodes AND (bootstrap config is DISABLED OR metadataUpdater.isBootstrapped() returns true). Typical when all brokers are removed from metadata or the initial bootstrap list resolved to nothing.

Common situations: All bootstrap servers are unreachable/wrong (DNS resolves to empty), broker cluster metadata is empty or corrupt, or the client connected but received no node information. Also happens if all nodes are in long backoff and metadata has been pruned.

Related errors


AI-assisted analysis of apache/kafka@996fb4585a (2026-08-11). Data as JSON: /api/errors/11801f442cdc6342. Report an issue: GitHub.

Appendix: source

Thrown at clients/src/main/java/org/apache/kafka/clients/NetworkClient.java:910

        } else if (foundCanConnect != null) {
            log.trace("Found least loaded node {} with no active connection", foundCanConnect);
            return new LeastLoadedNode(foundCanConnect, atLeastOneConnectionReady);
        } else {
            log.trace("Least loaded node selection failed to find an available node");
            return new LeastLoadedNode(null, atLeastOneConnectionReady);
        }
    }

    /**
     * Handle the case when there are no nodes available.
     * <p>
     * If bootstrap is disabled or already complete, throw IllegalStateException.
     * If bootstrap is enabled but not yet complete, return an empty {@link LeastLoadedNode}
     * so that the caller can continue polling while DNS resolution finishes.
     */
    private LeastLoadedNode handleEmptyNodeList() {
        if (bootstrapConfiguration == BootstrapConfiguration.DISABLED || metadataUpdater.isBootstrapped()) {
            throw new IllegalStateException("There are no nodes in the Kafka cluster");
        }

        log.debug("No nodes available yet, still in bootstrap phase");
        return new LeastLoadedNode(null, false);
    }

    public static AbstractResponse parseResponse(ByteBuffer responseBuffer, RequestHeader requestHeader) {
        try {
            return AbstractResponse.parseResponse(responseBuffer, requestHeader);
        } catch (BufferUnderflowException e) {
            throw new SchemaException("Buffer underflow while parsing response for request with header " + requestHeader, e);
        } catch (CorrelationIdMismatchException e) {
            if (SaslClientAuthenticator.isReserved(requestHeader.correlationId())
                && !SaslClientAuthenticator.isReserved(e.responseCorrelationId()))
                throw new SchemaException("The response is unrelated to Sasl request since its correlation id is "
                    + e.responseCorrelationId() + " and the reserved range for Sasl request is [ "
                    + SaslClientAuthenticator.MIN_RESERVED_CORRELATION_ID + ","
                    + SaslClientAuthenticator.MAX_RESERVED_CORRELATION_ID + "]");

View on GitHub (pinned to 996fb4585a)