# java.io.IOException: 无法连接到节点 -1 (localhost/127.0.0.1:9092)。代理可能不可用。

- **ID:** `kafka/network-exception-read-returned-negative`
- **领域:** kafka
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Kafka 客户端无法与代理建立 TCP 连接，通常是由于网络配置错误或代理宕机。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kafka 2.8.0 | active | — | — |
| Kafka 3.0.0 | active | — | — |
| Kafka 3.4.0 | active | — | — |

## 解决方案

1. ```
   Verify broker availability by running `telnet localhost 9092` or `nc -zv localhost 9092` to ensure the port is open. Then check broker logs for errors.
   ```
2. ```
   Update `bootstrap.servers` in the producer/consumer configuration to point to a correct, reachable broker list (e.g., `bootstrap.servers=broker1:9092,broker2:9092`).
   ```

## 无效尝试

- **Restarting the Kafka client without checking broker health** — The underlying broker issue (e.g., crash, network partition) remains unresolved, so the error recurs. (90% 失败率)
- **Increasing `request.timeout.ms` to a very high value** — A timeout extension does not fix the connection failure; it only delays the error message. (70% 失败率)
