# org.apache.kafka.common.errors.InterruptException：消费者拉取线程在重平衡期间被中断

- **ID:** `kafka/consumer-fetch-thread-interrupted-during-rebalance`
- **领域:** kafka
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 78%

## 根因

消费者后台拉取线程在组处于重平衡状态时被中断，通常是由于线程池关闭或poll()循环超时。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kafka 3.4.0 | active | — | — |
| Kafka 3.6.1 | active | — | — |
| Kafka 3.8.0 | active | — | — |

## 解决方案

1. ```
   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(); } });
   ```
2. ```
   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** — Increasing max.poll.interval.ms gives more time but doesn't address the thread interruption source. (85% 失败率)
- **Restarting the consumer application** — Restarting the consumer without fixing the thread pool management just re-triggers the same interruption. (95% 失败率)
