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

Abort signal thrown from zmq_send #100

Closed
raghav-sesh opened this issue Dec 9, 2016 · 7 comments
Closed

Abort signal thrown from zmq_send #100

raghav-sesh opened this issue Dec 9, 2016 · 7 comments

Comments

@raghav-sesh
Copy link

raghav-sesh commented Dec 9, 2016

The following is the string I'm trying to send as a message using zmq_send:
" Node[0]TC[0]: Thread tid 16814, cpu 14 started"

Intermittently, my program crashes only while sending this message, not for other messages. This string is generated using snprintf, so it is definitely NULL terminated.

Following is the stack trace of the crash:

#0 0x00007fa29b56d187 in raise () from /lib64/libc.so.6
#1 0x00007fa29b56e538 in abort () from /lib64/libc.so.6
#2 0x00007fa29ca9ba3e in zmq::zmq_abort(char const*) ()
from libzmq.so.4.2.0
#3 0x00007fa29caa4389 in zmq::msg_t::size() ()
from libzmq.so.4.2.0
#4 0x00007fa29cad1032 in zmq::v2_encoder_t::message_ready() ()
fromlibzmq.so.4.2.0
#5 0x00007fa29cac4801 in zmq::stream_engine_t::out_event() ()
from libzmq.so.4.2.0
#6 0x00007fa29ca9c8a4 in zmq::io_thread_t::in_event() ()
from libzmq.so.4.2.0
#7 0x00007fa29ca9b71e in zmq::epoll_t::loop() ()
from libzmq.so.4.2.0
#8 0x00007fa29cace915 in thread_routine ()
from libzmq.so.4.2.0
#9 0x00007fa2a18ec0a4 in start_thread () from /lib64/libpthread.so.0
#10 0x00007fa29b61d04d in clone () from /lib64/libc.so.6

I have reproduced the same with two version of zmq - 4.2.0 and 4.1.6.

@bluca
Copy link
Member

bluca commented Dec 9, 2016

What does the code look like? Do you have a minimal repro snippet?

@raghav-sesh
Copy link
Author

@bluca
It looks something like this:
char strLogMsg[256];
sprintf(strLogMsg, "Node[%d]TC[%d]: Thread tid %d, cpu %d started", NodeID_, tcID, tid, cpunum);
int rc = zmq_send(publisher,strLogMsg,strlen(strLogMsg)+1,0);

@bluca
Copy link
Member

bluca commented Dec 9, 2016

Are you sure the buffer is large enough? It might be overflowing

@raghav-sesh
Copy link
Author

It is large enough. Data size is only 46 bytes. But the container is created of size 256 bytes. It's an intermittent problem. Fails 50% of the time.

@raghav-sesh
Copy link
Author

raghav-sesh commented Dec 9, 2016

@bluca
I'm seeing a new stack trace as well:

(gdb) bt
#0 0x00007f2361cad187 in raise () from /lib64/libc.so.6
#1 0x00007f2361cae538 in abort () from /lib64/libc.so.6
#2 0x00007f23631c06e9 in zmq::zmq_abort(char const*) ()
from libzmq.so
#3 0x00007f23631c83cd in zmq::msg_t::add_refs(int) ()
from libzmq.so
#4 0x00007f23631bf943 in zmq::dist_t::distribute(zmq::msg_t*) ()
from libzmq.so
#5 0x00007f23631bfab2 in zmq::dist_t::send_to_matching(zmq::msg_t*) ()
from libzmq.so
#6 0x00007f23631eff81 in zmq::xpub_t::xsend(zmq::msg_t*) ()
from libzmq.so
#7 0x00007f23631daed2 in zmq::socket_base_t::send(zmq::msg_t*, int) ()
from libzmq.so
#8 0x00007f23631f2f2e in zmq_send ()
from libzmq.so
#9 0x00007f2366c7e5aa in postLog (
this=0x2872568, messageSize=47,
message=0x7f1fb06436c0 "Node[0]TC[0]: Thread tid 31032, cpu 14 started")

@bjovke
Copy link

bjovke commented Apr 9, 2017

First of all, you should not use sprintf() in your program AT ALL. Instead snprintf() should be always used, like this:

char strLogMsg[256];
snprintf(strLogMsg, 256, "Node[%d]TC[%d]: Thread tid %d, cpu %d started", NodeID_, tcID, tid, cpunum);
int rc = zmq_send(publisher,strLogMsg,strlen(strLogMsg)+1,0);

After you do it like this and the issue is still present then it could be discussed if there's something wrong with zmq_send().

@sigiesec
Copy link
Member

sigiesec commented Apr 5, 2018

Closing this due to inactivity. If you still have problems, please reopen and provide some more information on how to reproduce it, an executable test case would be best.

@sigiesec sigiesec closed this as completed Apr 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants