Kafka producer: TimeoutException: Expiring N record(s) for topic-partition
org.apache.kafka.common.errors.TimeoutExceptionExpiring 12 record(s) for orders-3:120001 ms has passed since batch creation. The request has not been sent, or no server response has been received yet.Records waited in the producer longer than delivery.timeout.ms (120 seconds by default) without being acknowledged, so the producer failed them. The producer could not reach the partition leader fast enough, or the broker did not answer.
Common causes
- The partition leader is unavailable or moving, so batches cannot be sent.How to confirm: Broker logs or kafka-topics --describe show the partition without a leader or with leadership changes at that time.
- The producer is sending faster than the brokers or network can accept, so batches queue up.How to confirm: Producer metrics show record-queue-time-avg close to the timeout and buffer-available-bytes near zero.
- Network or authentication problems between the client and the brokers.How to confirm: The client log shows repeated disconnects or authentication failures before the expiry.
How to fix it
Fix broker availability or network issues first; raising timeouts only delays the failure.
Give batches more time when brokers are healthy but slow, keeping delivery.timeout.ms at least linger.ms + request.timeout.ms.
| Setting | Default | Note |
|---|---|---|
delivery.timeout.ms | 120000 | |
request.timeout.ms | 30000 | |
linger.ms | 5 |
Reduce load per producer: more partitions, compression, or larger batches.
| Setting | Default | Note |
|---|---|---|
batch.size | 16384 | |
compression.type | none |
Where the message comes from
Sender.javainapache/kafkaat4.3.2- Message checked in Kafka clients 4.3.2. delivery.timeout.ms was added in Kafka 2.1 by KIP-91.
Message template in the source: Expiring %d record(s) for %s:%d ms has passed since batch creation. The request has not been sent, or no server response has been received yet.