Common Apache Kafka Exceptions and Their Causes
This article lists frequent Apache Kafka exceptions such as UnknownTopicOrPartitionException, LEADER_NOT_AVAILABLE, NotLeaderForPartitionException, TimeoutException, RecordTooLargeException, and others, explaining each error message, typical reasons, and practical troubleshooting steps for producers and consumers.
1、UnknownTopicOrPartitionException
org.apache.kafka.common.errors.UnknownTopicOrPartitionException:
This server does not host this topic-partitionError: Partition data not found.
Analysis: Producer sent messages to a non‑existent topic; verify the topic exists or enable auto.create.topics.enable.
2、LEADER_NOT_AVAILABLE
WARN Error while fetching metadata with correlation id 0 : {test=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClientError: Leader unavailable.
Analysis: Often occurs when the topic is being deleted or a leader election is in progress; use kafka-topics to check leader info and verify broker health, possibly restarting brokers.
3、NotLeaderForPartitionException
org.apache.kafka.common.errors.NotLeaderForPartitionException: This server is not the leader for that topic-partitionError: Broker is no longer the leader for the partition.
Analysis: Happens during leader changes; investigate why the leader switched between brokers.
4、TimeoutException
org.apache.kafka.common.errors.TimeoutException: Expiring 5 record(s) for test-0: 30040 ms has passeError: Request timed out.
Analysis: Check where the timeout originates, verify network connectivity, and consider increasing request.timeout.ms.
5、RecordTooLargeException
WARN async.DefaultEventHandler: Produce request with correlation id 92548048 failed due to [TopicName,1]: org.apache.kafka.common.errors.RecordTooLargeExceptionError: Message too large.
Analysis: Producer cannot handle the oversized message; increase request.timeout.ms or reduce batch.size.
6、Closing socket connection
Closing socket connection to/127,0,0,1.(kafka.network.Processor)Error: Connection closed.
Analysis: Mismatch between producer and consumer client versions can cause repeated errors; ensure compatible versions.
7、ConcurrentModificationException
java.util.ConcurrentModificationException: KafkaConsumer is not safe for multi-threaded accessError: Thread‑unsafe consumer usage.
Analysis: KafkaConsumer is not thread‑safe; avoid sharing a consumer across threads.
8、NetWorkException
[kafka-producer-network-thread | producer-1] o.apache.kafka.common.network.Selector : [Producer clientId=producer-1] Connection with / disconnectedError: Network exception.
Analysis: Network connection interrupted; check broker network status.
9、ILLEGAL_GENERATION
ILLEGAL_GENERATION occurred while committing offsets for groupError: Invalid generation.
Analysis: Consumer missed a rebalance because it spent too much time processing data; reduce max.poll.records, increase max.poll.interval.ms, or speed up processing.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Big Data Technology & Architecture
Wang Zhiwu, a big data expert, dedicated to sharing big data technology.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
