Kafka Exception LeaderNotAvailableException
org.apache.kafka.common.errors.LeaderNotAvailableException
Retriable
Broker
There is no currently available leader for the given partition (either because a leadership election is in progress or because all replicas are down).
Common Causes
- Partition leader election in progress after a broker restart, crash, or controlled shutdown
- Preferred leader election running via kafka-preferred-replica-election.sh or auto.leader.rebalance.enable triggered a momentary gap
- New topic just created; partition leaders not yet elected (brief window during topic creation)
Solutions
- This error is transient and retriable — ensure client 'retries' is set high enough (>=3) and 'retry.backoff.ms' is at least 100ms to survive election windows
- Monitor unclean leader elections with JMX metric 'UncleanLeaderElectionsPerSec'; if non-zero, investigate broker stability and ensure 'unclean.leader.election.enable=false'
- If persistent after broker restart, check 'kafka-topics.sh --describe' for partitions showing 'Leader: none' and manually trigger preferred replica election
Example Stack Trace
org.apache.kafka.common.errors.LeaderNotAvailableException: There is no leader for this topic-partition as we are in the middle of a leadership election.Diagnostic Commands
# Check for partitions without a leader
kafka-topics.sh --describe --topic <topic> --bootstrap-server localhost:9092 | grep 'Leader: none'
# Check for under-replicated partitions
kafka-topics.sh --describe --bootstrap-server localhost:9092 --under-replicated-partitionsRelated
Protocol error: LEADER_NOT_AVAILABLE (code 5)
Related Broker exceptions: CorruptRecordException · FencedLeaderEpochException · NetworkException · NotEnoughReplicasAfterAppendException · NotEnoughReplicasException · NotLeaderOrFollowerException · TimeoutException · UnknownLeaderEpochException
Hitting
LeaderNotAvailableException in production? Conduktor Console gives you real-time visibility into clients, consumer groups, and broker health. Browse every Kafka exception or protocol error code.