kafka network_error ai_generated true

java.io.IOException: Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.common.errors.TimeoutException)

ID: kafka/network-exception-read-returned-negative

Also available as: JSON · Markdown · 中文
85%Fix Rate
85%Confidence
1Evidence
2023-04-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Kafka 2.8.0 active
Kafka 3.0.0 active
Kafka 3.4.0 active

Root Cause

The Kafka client cannot establish a TCP connection to the broker, often due to network misconfiguration or broker downtime.

generic

中文

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

Official Documentation

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

Workarounds

  1. 85% success 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.
    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. 90% success Update `bootstrap.servers` in the producer/consumer configuration to point to a correct, reachable broker list (e.g., `bootstrap.servers=broker1:9092,broker2:9092`).
    Update `bootstrap.servers` in the producer/consumer configuration to point to a correct, reachable broker list (e.g., `bootstrap.servers=broker1:9092,broker2:9092`).

中文步骤

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

Dead Ends

Common approaches that don't work:

  1. Restarting the Kafka client without checking broker health 90% fail

    The underlying broker issue (e.g., crash, network partition) remains unresolved, so the error recurs.

  2. Increasing `request.timeout.ms` to a very high value 70% fail

    A timeout extension does not fix the connection failure; it only delays the error message.