简体   繁体   English

librdkafka线程无法在失败时清除

[英]librdkafka threads not cleaning up on failure

In my application i am creating one producer and one consumer. 在我的应用程序中,我正在创建一个生产者和一个消费者。

conf->set("dr_cb", delivery_cb, errstr);
conf->set("event_cb", event_cb, errstr);

RdKafka::Producer::create(conf.get(), errstr)

conf->set("log_level", "0", errstr);
conf->set("group.id", group_id, errstr);
conf->set("client.id", m_kafka_client_id, errstr);
conf->set("auto.offset.reset", "earliest", errstr);
conf->set("rebalance_cb", rebalance_cb, errstr);
conf->set("statistics.interval.ms", "3000", errstr);
conf->set("event_cb", event_cb, errstr);

RdKafka::KafkaConsumer::create(conf.get(), errstr)

then i try to fetch metadata as follows 然后我尝试如下获取元数据

err = _consumer->metadata(false, nullptr, &metadata, METADATA_TIMEOUT); 
std::unique_ptr<RdKafka::Metadata> metadata_uptr(metadata); // Handover the raw pointer to the unique_ptr now

if for some reason broker communication is not working i get error message then i producer and consumer get's deleted through unique_ptr -> destructor. 如果由于某种原因经纪人沟通不起作用,我会收到错误消息,然后我的生产者和消费者将通过unique_ptr->析构函数删除。 and then this goes in a loop till application successfully connects to brokers. 然后进入循环直到应用程序成功连接到代理。

what i have observed is i see lot's of threads getting created and remain there. 我观察到的是,我看到许多线程正在创建并保留在那里。 at one point of time the count reached 2000 threads. 在某个时间点,计数达到2000个线程。

What is the correct way to cleanup Kafka? 清理Kafka的正确方法是什么?

the threads are stuck here 线程卡在这里

#0  0x00007f6acc031cf2 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x00000000004b8e65 in cnd_timedwait_ms (cnd=cnd@entry=0xab41b8, mtx=mtx@entry=0xab4190, timeout_ms=<optimized out>) at tinycthread.c:501
#2  0x00000000004853aa in rd_kafka_q_serve (rkq=0xab4190, timeout_ms=<optimized out>, max_cnt=max_cnt@entry=0, cb_type=cb_type@entry=RD_KAFKA_Q_CB_CALLBACK, 
callback=callback@entry=0x0, opaque=opaque@entry=0x0) at rdkafka_queue.c:440
#3  0x000000000045a43c in rd_kafka_thread_main (arg=arg@entry=0xabf760) at rdkafka.c:1227
#4  0x00000000004b8c07 in _thrd_wrapper_function (aArg=<optimized out>) at tinycthread.c:624
#5  0x00007f6acc02de25 in start_thread () from /lib64/libpthread.so.0
#6  0x00007f6acaa7834d in clone () from /lib64/libc.so.6

i also tried calling following routine on failure but no help... 我也尝试在失败后拨打以下例程,但没有帮助...

RdKafka::wait_destroyed(5000);

RdKafka::KafkaConsumer was wrapped inside another container and "myobject_wrapper->close()" was not getting redirected to "RdKafka::KafkaConsumer::close" RdKafka :: KafkaConsumer包装在另一个容器中,并且“ myobject_wrapper-> close()”未重定向到“ RdKafka :: KafkaConsumer :: close”

after fixing the this issue in my application, things are working fine now. 在我的应用程序中解决此问题后,现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM