Big Data 5 min read

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.

Big Data Technology & Architecture
Big Data Technology & Architecture
Big Data Technology & Architecture
Common Apache Kafka Exceptions and Their Causes

1、UnknownTopicOrPartitionException

org.apache.kafka.common.errors.UnknownTopicOrPartitionException:
This server does not host this topic-partition

Error: 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.NetworkClient

Error: 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-partition

Error: 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 passe

Error: 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.RecordTooLargeException

Error: 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 access

Error: 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 / disconnected

Error: Network exception.

Analysis: Network connection interrupted; check broker network status.

9、ILLEGAL_GENERATION

ILLEGAL_GENERATION occurred while committing offsets for group

Error: 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Big DataKafkaConsumerError HandlingProducerExceptions
Big Data Technology & Architecture
Written by

Big Data Technology & Architecture

Wang Zhiwu, a big data expert, dedicated to sharing big data technology.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.