Skip to content
Kafka Is Fun

ScenarioProduction Scenarios

How would you debug a 'Network Exception: Disconnected' error in a Kafka producer?

Reference answer

NetworkException is a retriable error for a network-related IOException while making a request; the Javadoc notes it can happen when the client's metadata is out of date and it sends a request to a node that is now dead. Possible causes: 1) A broker restart, crash or leader move, so the connection drops and metadata is stale. 2) An idle connection closed: clients and brokers close idle connections (producer connections.max.idle.ms default 540000, 9 minutes; broker default 600000, 10 minutes), and a load balancer or firewall with a shorter idle timeout can drop them silently. 3) Network instability. 4) A slow or overloaded broker causing request timeouts (request.timeout.ms, default 30 seconds). Debug: 1) Check broker logs and whether a broker restarted at that time. 2) Compare connections.max.idle.ms with the load balancer or firewall idle timeout. 3) Look at reconnect.backoff.ms (default 50) and reconnect.backoff.max.ms (default 1000) to see how fast the client reconnects. 4) Check broker RequestHandlerAvgIdlePercent (ideally above 0.3) for overload. Fix: keep connections.max.idle.ms below the load balancer or firewall idle timeout, or enable TCP keepalive there. The producer retries retriable errors within delivery.timeout.ms (default 120 seconds), so occasional occurrences are absorbed.

Expected key concepts: NetworkException, retriable, connections.max.idle.ms, load balancer, firewall, idle timeout, broker restart, request.timeout.ms, reconnect.backoff.ms, RequestHandlerAvgIdlePercent, delivery.timeout.ms

How did that feel?

Your own verdict, not the score. It shows up next to this question in the list, so you can come back to the shaky ones.