Skip to content
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

crashed when destroy headers #239

Open
huth511 opened this issue Aug 21, 2024 · 1 comment
Open

crashed when destroy headers #239

huth511 opened this issue Aug 21, 2024 · 1 comment

Comments

@huth511
Copy link

huth511 commented Aug 21, 2024

I created headers in a local function, and their values were created by dynamically allocating memory in the heap. Then, I store these pointers ( and I‘ve never freed them ):

        long n1;
        long n2;
        kafka::Headers headers;
        auto pN1Bytes = (decltype(n1)*)malloc(sizeof(n1));
        *pN1Bytes = n1;
        auto pN2Bytes = (decltype(n2)*)malloc(sizeof(n2));
        *pN2Bytes = n2;
        headers.push_back(kafka::Header(kafka::Header::Key("n1"), kafka::Header::Value(pN1Bytes, sizeof(n1))));
        headers.push_back(kafka::Header(kafka::Header::Key("n2"), kafka::Header::Value(pN2Bytes, sizeof(n2))));

but it occasionally crashes in rd_kafka_headers_destroy, here is the stack:
1724227362589

I sent msg using the following method, and this method is called sequentially:

bool KafkaProducerService::Produce(const kafka::Key& key, const std::string& msg, const std::string& topic, const kafka::Headers& headers)
{
    auto ret = true;
    try {
        auto record = kafka::clients::producer::ProducerRecord(topic, mPartition, key, kafka::Value(msg.c_str(), msg.size()));
        record.headers() = headers;
        mpProducer->send(
            record,
            mProduceCallback,
            kafka::clients::producer::KafkaProducer::SendOption::ToCopyRecordValue,
            kafka::clients::producer::KafkaProducer::ActionWhileQueueIsFull::NoBlock
        );
        mpProducer->flush(std::chrono::milliseconds(50));
    }
    catch (const kafka::KafkaException& e) {
        std::cerr << "% Unexpected exception caught: " << e.what() << std::endl;
        ret = false;
    }

    return ret;
}
  • version:
    -- mordern-cpp-kafka: v2024.07.03
    -- librdkafka: 2.4.0
@huth511
Copy link
Author

huth511 commented Oct 14, 2024

It was crashed when topic deleted (err: UNKNOWN TOPIC)

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

No branches or pull requests

1 participant