3
votes

running Confluent Kafka 4.1.1 community.

I have...

  • min in-sync replicas = 2
  • Topic: 1 partition, replica count 3
  • Total of 3 brokers.
  • Producer is set to acks = -1
  • All other producer settings are default.

I launch my application and as it starts to write records to Kafka I down one of the brokers on purpose and I immediately get: org.apache.kafka.common.errors.NetworkException: The server disconnected before a response was received.

Based on the settings above. shouldn't the producer write() succeed this and not throw an error?

Clarification

  • I kill a broker on purpose
  • This only seems happens if the leader broker is killed?
2
have you seen this?senseiwu
Yes and it's not exactly what happens with me. I am on purpose killing one of the Kafka brokers and based on my config above I'm expecting the write to succeed. I think it has to do with killing the leader node. I picked it by chance.user432024
All writes and reads must communicate with the leader, so failure would be expectedOneCricketeer
Yep seems like it.user432024

2 Answers

3
votes

Without seeing full config. and log messages, hard to say, still..

In Kafka, all writes go through the leader partition. In your setting, out of 3 brokers, you killed 1. So it should be possible to write successfully to the remaining 2 and get acknowledgement. But in case the broker which has been killed is the leader node, it can result in an exception.

From the docs:

acks=all This means the leader will wait for the full set of in-sync replicas to acknowledge the record. This guarantees that the record will not be lost as long as at least one in-sync replica remains alive. This is the strongest available guarantee.

You can in any case set retries to a value higher than 0 and see the behaviour - a new leader should be elected and your write should be eventually succeed

2
votes

For Spring Cloud Stream for kafka binder for Azure Eventhub for Kafka
Exception:

{"timestamp":"2020-09-23 23:37:18.541","level":"ERROR","class":"org.springframework.kafka.support.LoggingProducerListener.onError 84", "thread":"kafka-producer-network-thread | producer-2","traceId":"","message":Exception thrown when sending a message with key='null' and payload='{123, 34, 115, 116, 97, 116, 117, 115, 34, 58, 34, 114, 101, 97, 100, 121, 34, 44, 34, 101, 118, 101...' to topic executor-networkexception and partition 3:}
org.apache.kafka.common.errors.NetworkException: The server disconnected before a response was received.

{"timestamp":"2020-09-23 23:37:18.545","level":"WARN ","class":"org.apache.kafka.clients.producer.internals.Sender.completeBatch 568", "thread":"kafka-producer-network-thread | producer-2","traceId":"","message":[Producer clientId=producer-2] Received invalid metadata error in produce request on partition executor-networkexception-3 due to org.apache.kafka.common.errors.NetworkException: The server disconnected before a response was received.. Going to request metadata update now}

Solution: setup idle time, retry count, retry backoff time -

spring:
  cloud:
    stream:
      kafka:
        binder:
          brokers: srsmvsdneventhubstage.servicebus.windows.net:9093
          configuration:
            sasl.jaas.config: 'org.apache.kafka.common.security.plain.PlainLoginModulerequiredusername="$ConnectionString"password="Endpoint=sb://xxxxx.servicebus.windows.net/;=";'
            sasl.mechanism: PLAIN
            security.protocol: SASL_SSL
            retries: 3
            retry.backoff.ms: 60
            connections.max.idle.ms: 240000

Reference:

http://kafka.apache.org/090/documentation.html (read http://kafka.apache.org/090/documentation.html#producerconfigs)

    [https://github.com/Azure/azure-event-hubs-for-kafka/blob/master/CONFIGURATION.md][2]  (read connections.max.idle.ms)

Logs:

"org.apache.kafka.clients.producer.ProducerConfig.logAll 279", "thread":"hz._hzInstance_1_dev.cached.thread-14","traceId":"","message":ProducerConfig values: 
        acks = 1
        batch.size = 16384
        bootstrap.servers = [srsmvsdneventhubstage.servicebus.windows.net:9093]
        buffer.memory = 33554432
        client.id = 
        compression.type = none
        connections.max.idle.ms = 540000
        enable.idempotence = false
        interceptor.classes = []
        key.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
        linger.ms = 0
        max.block.ms = 60000
        max.in.flight.requests.per.connection = 5
        max.request.size = 1048576
        metadata.max.age.ms = 300000
        metric.reporters = []
        metrics.num.samples = 2
        metrics.recording.level = INFO
        metrics.sample.window.ms = 30000
        partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
        receive.buffer.bytes = 32768
        reconnect.backoff.max.ms = 1000
        reconnect.backoff.ms = 50
        request.timeout.ms = 30000
        retries = 0
        retry.backoff.ms = 100
        sasl.client.callback.handler.class = null
        sasl.jaas.config = [hidden]
        sasl.kerberos.kinit.cmd = /usr/bin/kinit
        sasl.kerberos.min.time.before.relogin = 60000
        sasl.kerberos.service.name = null
        sasl.kerberos.ticket.renew.jitter = 0.05
        sasl.kerberos.ticket.renew.window.factor = 0.8
        sasl.login.callback.handler.class = null
        sasl.login.class = null
        sasl.login.refresh.buffer.seconds = 300
        sasl.login.refresh.min.period.seconds = 60
        sasl.login.refresh.window.factor = 0.8
        sasl.login.refresh.window.jitter = 0.05
        sasl.mechanism = PLAIN
        security.protocol = SASL_SSL
        send.buffer.bytes = 131072
        ssl.cipher.suites = null
        ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
        ssl.endpoint.identification.algorithm = https
        ssl.key.password = null
        ssl.keymanager.algorithm = SunX509
        ssl.keystore.location = null
        ssl.keystore.password = null
        ssl.keystore.type = JKS
        ssl.protocol = TLS
        ssl.provider = null
        ssl.secure.random.implementation = null
        ssl.trustmanager.algorithm = PKIX
        ssl.truststore.location = null
        ssl.truststore.password = null
        ssl.truststore.type = JKS
        transaction.timeout.ms = 60000
        transactional.id = null
        value.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
    }

New-

"org.apache.kafka.clients.producer.ProducerConfig.logAll 279", "thread":"hz._hzInstance_1_dev.cached.thread-20","traceId":"","message":ProducerConfig values: 
            acks = 1
            batch.size = 16384
            bootstrap.servers = [xxxxx.servicebus.windows.net:9093]
            buffer.memory = 33554432
            client.id = 
            compression.type = none
            **connections.max.idle.ms = 240000**
            enable.idempotence = false
            interceptor.classes = []
            key.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
            linger.ms = 0
            max.block.ms = 60000
            max.in.flight.requests.per.connection = 5
            max.request.size = 1048576
            metadata.max.age.ms = 300000
            metric.reporters = []
            metrics.num.samples = 2
            metrics.recording.level = INFO
            metrics.sample.window.ms = 30000
            partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
            receive.buffer.bytes = 32768
            reconnect.backoff.max.ms = 1000
            reconnect.backoff.ms = 50
            request.timeout.ms = 30000
            **retries = 3**
            **retry.backoff.ms = 60**
            sasl.client.callback.handler.class = null
            sasl.jaas.config = [hidden]
            sasl.kerberos.kinit.cmd = /usr/bin/kinit
            sasl.kerberos.min.time.before.relogin = 60000
            sasl.kerberos.service.name = null
            sasl.kerberos.ticket.renew.jitter = 0.05
            sasl.kerberos.ticket.renew.window.factor = 0.8
            sasl.login.callback.handler.class = null
            sasl.login.class = null
            sasl.login.refresh.buffer.seconds = 300
            sasl.login.refresh.min.period.seconds = 60
            sasl.login.refresh.window.factor = 0.8
            sasl.login.refresh.window.jitter = 0.05
            sasl.mechanism = PLAIN
            security.protocol = SASL_SSL
            send.buffer.bytes = 131072
            ssl.cipher.suites = null
            ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
            ssl.endpoint.identification.algorithm = https
            ssl.key.password = null
            ssl.keymanager.algorithm = SunX509
            ssl.keystore.location = null
            ssl.keystore.password = null
            ssl.keystore.type = JKS
            ssl.protocol = TLS
            ssl.provider = null
            ssl.secure.random.implementation = null
            ssl.trustmanager.algorithm = PKIX
            ssl.truststore.location = null
            ssl.truststore.password = null
            ssl.truststore.type = JKS
            transaction.timeout.ms = 60000
            transactional.id = null
            value.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
        }