Kafka Error LEADER_NOT_AVAILABLE
Error code 5 · Retriable Broker
There is no leader for this topic-partition as we are in the middle of a leadership election.
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
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 APIs
This error can be returned by: Fetch · ListOffsets · Metadata · Produce
Debugging Kafka errors? Conduktor Console gives you real-time visibility into your cluster. Explore all errors in the Error Decoder.