-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Some corruption in logger callback? #70
Comments
Quick update - I put a mutex around the logging and it didn't help - still getting some null characters sometimes. Hopefully you know what the problem is and have a quick fix? |
Can you provide an example of such logs? |
Are you holding on to the 'fac' or 'buf' from the log callback after your callback has returned? |
I'm passing them on to my own logger as effectively On Monday, February 3, 2014, Magnus Edenhill notifications@github.com
|
I'll see if I can get the logs to you (as you know that's a struggle). On Monday, February 3, 2014, Dan Hoffman hoffmandan@gmail.com wrote:
|
The log strings are always nul-terminated and they will be constant for the duration of the callback. |
I copied over the rdkafka_performance and added the logger callback. so far unable to reproduce it - will keep you posted. |
So far it's something funky with va_list/va_arg handling. Not sure why it only happens with logs coming from the logger callback. Might be getting lucky elsewhere. |
I can have a look at the piece of code and see if I can spot the problem. |
This is effectively what I'm doing (I've stripped off a bunch of useful stuff so it may look strange that I'm bothering to split it out into multiple functions, etc.). Assume that myfile is an int and has already been ::open()-ed to a file called myfile.txt. Also assume I registered for the logging callback and asked for 'all'.
On my host, If you run this for a long time and then grep 'meta' myfile.txt, it will tell you that it's binary. if you 'od -a myfile.txt | grep nul'. You'll see that there are null characters.
Again - I'm not sure if there's anything wrong with librdkafka or that my va_list stuff is wrong. Either way, hope you can find it :) |
There is a stray va_end(ap) in writeit(), but I guess thats a cut'n'paste error (it doesnt matter though). I think this is a thread race problem with your static buffer in writeit. I think you can fix this issue by adding the __thread attribute to the static buffer (and any other static stuff you use in this callchain which is edited out): static __thread char rLogBufFORCOLLECTOR_OOB[16384]; That will put rLogBufFORCOLL... in a thread local storage (TLS) and avoid two threads accessing it simultaneously. |
the va_end wasn't stray. I saw in the man pages that vsprintf doesn't call va_end so I thought it was the right thing to do. In any case, I'm trying the __thread thing now. appreciate the help. |
Making them non-static seemed to do the trick. Thanks very much for the help. |
Cool :) As long as you dont return a non-static from that writeit function. |
Yeah, didn't need a return to begin with so all good. On Monday, February 3, 2014, Magnus Edenhill notifications@github.com
|
Hi,
I'm finding that I'm occasionally getting some null characters when I'm logging to file the contents of the logger callback. My program is single threaded, yet I know librdkafka is multi-threaded. Do I have to do any locking while dealing with the logging callback? or are you locking while calling the callback handler?
Thanks.
The text was updated successfully, but these errors were encountered: