# org.apache.kafka.common.errors.NetworkException: 服务器在收到响应前断开连接。超时时间：30000 毫秒

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

## 根因

Kafka 代理在发送响应前关闭了 TCP 连接，通常是由于请求超时或客户端与代理之间的网络拥塞。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| kafka_2.13-3.3.1 | active | — | — |
| kafka_2.13-3.4.0 | active | — | — |
| kafka_2.13-3.5.0 | active | — | — |

## 解决方案

1. ```
   Increase `broker.request.timeout.ms` in `server.properties` (e.g., from 30000 to 60000) and restart the broker to allow longer processing time for slow requests.
   ```
2. ```
   Enable TCP keepalive on both client and broker: set `socket.connection.setup.timeout.ms=10000` and `socket.connection.setup.timeout.max.ms=30000` in `server.properties`, and on the client set `connections.max.idle.ms=300000`.
   ```
3. ```
   If using a load balancer, check idle timeout settings (e.g., AWS NLB idle timeout) and increase them to match Kafka's `connections.max.idle.ms`.
   ```

## 无效尝试

- **** — The timeout is on the broker side; increasing client timeout does not prevent the broker from disconnecting. (85% 失败率)
- **** — Network issues (e.g., firewall, TCP keepalive) persist after reboot; the error recurs on the next request. (90% 失败率)
- **** — Disabling socket timeout can cause resource exhaustion and does not address the root cause of disconnection. (70% 失败率)
