Skip to content

Unable to catch python timeout error #1222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
7 tasks
zaheer032 opened this issue Oct 12, 2021 · 1 comment
Closed
7 tasks

Unable to catch python timeout error #1222

zaheer032 opened this issue Oct 12, 2021 · 1 comment
Labels

Comments

@zaheer032
Copy link

zaheer032 commented Oct 12, 2021

Description

Unable to catch Kafka timeout error

How to reproduce

My confluent-kafka python- version 1.7.0 producer code is as below

from confluent_kafka import KafkaError, KafkaException

def publish_data():

   try:

        producer.produce(
            topic=topic,
            value={"produced_epoch": produced_epoch },
        )
        producer.flush()
    except (KafkaError, RuntimeError, KafkaException, Exception) as e:
        logging.error(f'Error publishing to kafka : {e}')
        return False
    return True

While producing the code I am getting the below error in Kafka broker

%5|1634047381.445|REQTMOUT|rdkafka#producer-1| [thrd:ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2]: ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2: Timed out ProduceRequest in flight (after 60844ms, timeout #0) %5|1634047381.445|REQTMOUT|rdkafka#producer-1| [thrd:ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2]: ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2: Timed out ProduceRequest in flight (after 60837ms, timeout #1) %5|1634047381.445|REQTMOUT|rdkafka#producer-1| [thrd:ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2]: ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2: Timed out ProduceRequest in flight (after 60816ms, timeout #2) %5|1634047381.445|REQTMOUT|rdkafka#producer-1| [thrd:ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2]: ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2: Timed out ProduceRequest in flight (after 60809ms, timeout #3) %5|1634047381.445|REQTMOUT|rdkafka#producer-1| [thrd:ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2]: ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2: Timed out ProduceRequest in flight (after 60788ms, timeout #4) %4|1634047381.445|REQTMOUT|rdkafka#producer-1| [thrd:ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2]: ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2: Timed out 31 in-flight, 0 retry-queued, 0 out-queue, 0 partially-sent requests %3|1634047381.445|FAIL|rdkafka#producer-1| [thrd:ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2]: ssl://kafka-kafka-2.kafka-kafka-brokers.kafka.svc:9093/2: 31 request(s) timed out: disconnect (after 108069ms in state UP)

I want to catch the REQTMOUT error and return False when error. But unable to do the same. Can anyone help me with it.

Checklist

Please provide the following information:

  • confluent-kafka-python : 1.7.0 with librdkafka
  • Apache Kafka broker version:
  • Client configuration: {...}
  • Operating system: linux
  • Provide client logs (with 'debug': '..' as necessary)
  • Provide broker log excerpts
  • Critical issue
@jliunyu
Copy link
Contributor

jliunyu commented Feb 14, 2022

Hi @zaheer032 , thanks for asking.

On_delivery callback will be a good idea to catch up the MSG_TIMED_OUT errors and in the event librdkafka is unable to contact any of the brokers a _ALL_BROKERS_DOWN err will be returned to the err_cb.

The answer You also don't need to worry about retries or reconnects as these are also handled by librdkafka client. In the event librdkafka is unable to contact any of the brokers a _ALL_BROKERS_DOWN err will be returned to the err_cb. If this goes on for too long you will start to see _MSG_TIMED_OUT errors in your delivery reports as well. This means that retries have been exhausted and you'll need to decide what you want to do with the message contents at that point. from #539 (comment) is still good for this one.

Example for error_cb: https://github.com/confluentinc/confluent-kafka-python/blob/master/tests/test_Producer.py#L10
Example for on_delivery callback: https://github.com/confluentinc/confluent-kafka-python/blob/master/tests/test_Producer.py#L29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants