# org.apache.kafka.common.errors.ZooKeeperConnectionLossException：KRaft控制器选举期间连接丢失

- **ID:** `kafka/zookeeper-connection-loss-during-kraft-election`
- **领域:** kafka
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在KRaft迁移或混合模式操作期间，ZooKeeper连接丢失中断了控制器选举过程，导致集群没有领导者。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kafka 3.5.0 | active | — | — |
| Kafka 3.6.0 | active | — | — |
| Kafka 3.7.0 | active | — | — |

## 解决方案

1. ```
   Restart the KRaft controller process with 'bin/kafka-server-stop.sh && bin/kafka-server-start.sh config/kraft/server.properties' to force a new election.
   ```
2. ```
   Ensure ZooKeeper quorum is stable and network latency between ZooKeeper and Kafka brokers is below 10ms. Use 'echo stat | nc zookeeper-host 2181' to check ZooKeeper state.
   ```

## 无效尝试

- **Restarting only ZooKeeper servers** — Restarting ZooKeeper alone does not re-trigger the KRaft election; the controller process must be restarted. (90% 失败率)
- **Raising zookeeper.session.timeout.ms** — Increasing ZooKeeper session timeout delays the failure but does not prevent connection loss due to network issues. (80% 失败率)
