kafka
runtime_error
ai_generated
true
org.apache.kafka.common.errors.InterruptException:消费者拉取线程在重平衡期间被中断
org.apache.kafka.common.errors.InterruptException: Consumer fetch thread interrupted during rebalance
ID: kafka/consumer-fetch-thread-interrupted-during-rebalance
78%修复率
83%置信度
1证据数
2024-05-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Kafka 3.4.0 | active | — | — | — |
| Kafka 3.6.1 | active | — | — | — |
| Kafka 3.8.0 | active | — | — | — |
根因分析
消费者后台拉取线程在组处于重平衡状态时被中断,通常是由于线程池关闭或poll()循环超时。
English
A consumer's background fetch thread was interrupted while the group was in a rebalance state, often due to thread pool shutdown or timeout in poll() loop.
官方文档
https://kafka.apache.org/documentation/#consumerconfigs_max.poll.interval.ms解决方案
-
Use a dedicated thread pool for consumer operations and ensure graceful shutdown with consumer.wakeup() before interrupting threads. Example: ExecutorService executor = Executors.newSingleThreadExecutor(); executor.submit(() -> { try { while (true) { consumer.poll(Duration.ofMillis(100)); } } catch (WakeupException e) { consumer.close(); } }); -
Set session.timeout.ms and max.poll.interval.ms to values that give the consumer enough time to complete processing before rebalance interrupts.
无效尝试
常见但无效的做法:
-
Raising max.poll.interval.ms to 10 minutes
85% 失败
Increasing max.poll.interval.ms gives more time but doesn't address the thread interruption source.
-
Restarting the consumer application
95% 失败
Restarting the consumer without fixing the thread pool management just re-triggers the same interruption.