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

Running multi-threaded producer gets into Segmentation Fault #9

Open
ShikhaSrivastava opened this issue Jul 31, 2014 · 4 comments
Open

Comments

@ShikhaSrivastava
Copy link

Hi,

I have been trying to run the modified version of SimpleProducer.cc (as per my requirements). When I am trying to run with 2 or more threads and sending 100,000 messages/thread or more, it is throwing segmentation fault when deleting a request (happens at different times and random). This error is not there while running a single thread.

The code where is throws error is -

        std::string data = "This is a test message.";
        Message *m = createMessage(data.c_str(), strlen(data));
        Message **messageArray = &m;

        ProduceRequest *request = createProduceRequest(string(topic_name), messageArray, 1);
        ProduceResponse *response;
        if( request != NULL ){
            response = c->sendProduceRequest(request); 
        } 

        if (response == NULL)
        {
            cerr << "an error ocurred while sending the produce request, errno = " << strerror(errno) << "\n";
        }
        else
        {
            if (response->hasErrorCode())
                cerr << "publish error detected here 1\n";
            else
                cout << "thread : " << boost::this_thread::get_id() << " : " << i << " : message successfully published to kafka\n";
        }
        if (response != NULL){
                delete response;
        } 
        if (request != NULL) {
                delete request; //seg fault here!!
        }

On taking a backtrace in gdb, I see that it throws error in-
~ProduceRequest() in ProduceRequest.cc class of libkafka package.

Since, the behavior is so random, I am not sure what is wrong. Has anyone tried it before?

Thanks,
Shikha

@ShikhaSrivastava
Copy link
Author

I tried serializing the for loop above to verify my code. It runs fine then. It is able to send >1000000/thread when I am using 4 threads.

Looks like a thread safety issue in the libkafka library to me.

Please share your opinion. Any help would be appreciated!

Thanks,
Shikha

@DavidTompkins
Copy link
Member

Hi Shikha,

How's it going? I'm glad to hear you are finding libkafka useful. I haven't
run experiments/tests in the manner you describe, so I am not sure what
assistance I can offer. However, if you can give me a pull request for a
test case to add to the test suite (i.e. it runs under the make check
rule), I will see what I can do to debug it.

-DT

On Thu, Jul 31, 2014 at 2:34 PM, ShikhaSrivastava [email protected]
wrote:

I tried serializing the for loop above to verify my code. It runs fine
then. It is able to send >1000000/thread when I am using 4 threads.

Looks like a thread safety issue in the libkafka library to be.

Please share your opinion. Any help would be appreciated!

Thanks,
Shikha


Reply to this email directly or view it on GitHub
#9 (comment)
.

@ShikhaSrivastava
Copy link
Author

Hi David,

Thanks for writing back. I have a test set ready that you can add to the library for thread safety. For now, I switched my application to multi process application to achieve the goal of the problem statement.
But if you can debug this issue and incorporate it in your next release, we would want to go towards a multi-threading application.

-Shikha

@ShikhaSrivastava
Copy link
Author

Hi David,

I tried creating a pull request to include the changes for dynamic buffer allocation to the repo. But somehow I am not able to create a new branch to commit my code to. Can you please help?

Thanks,
Shikha

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

2 participants