kafka network_error ai_generated true

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

org.apache.kafka.common.errors.NetworkException: The server disconnected before a response was received. Timeout: 30000 ms

ID: kafka/network-exception-read-timeout

其他格式: JSON · Markdown 中文 · English
82%修复率
88%置信度
1证据数
2023-06-20首次发现

版本兼容性

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

根因分析

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

English

Kafka broker closed the TCP connection before sending a response, often due to request timeout or network congestion between client and broker.

generic

官方文档

https://kafka.apache.org/documentation/#networking

解决方案

  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`.

无效尝试

常见但无效的做法:

  1. 85% 失败

    The timeout is on the broker side; increasing client timeout does not prevent the broker from disconnecting.

  2. 90% 失败

    Network issues (e.g., firewall, TCP keepalive) persist after reboot; the error recurs on the next request.

  3. 70% 失败

    Disabling socket timeout can cause resource exhaustion and does not address the root cause of disconnection.