zeromq / zmqpp

0mq 'highlevel' C++ bindings

Home Page:http://zeromq.github.io/zmqpp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

static context in actor causes abort on app close for static builds

aaronovz1 opened this issue · comments

commented

When compiling against latest libzmq release 4.2.3, static builds throw an abort on app closure when destructing the static context in actor (actor_pipe_ctx_).

I believe this is because libzmq now has a global static mutex in random.cpp (random_sync) and it is being destructed before actor_pipe_ctx_ because the order of destruction of these globals can not be controlled.

Program received signal SIGABRT, Aborted.
0x00007ffff5534428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
54  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) list
49  in ../sysdeps/unix/sysv/linux/raise.c
(gdb) bt
#0  0x00007ffff5534428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
#1  0x00007ffff553602a in __GI_abort () at abort.c:89
#2  0x00000000012f39ee in zmq::zmq_abort (errmsg_=errmsg_@entry=0x7ffff568c10a "Invalid argument") at src/err.cpp:87
#3  0x00000000012fde65 in zmq::mutex_t::lock (this=0x4431200 <random_sync>) at src/mutex.hpp:122
#4  zmq::scoped_lock_t::scoped_lock_t (mutex_=..., this=<synthetic pointer>) at src/mutex.hpp:168
#5  zmq::random_close () at src/random.cpp:110
#6  0x00000000012ee546 in zmq::ctx_t::~ctx_t (this=0x61600000f980, __in_chrg=<optimized out>) at src/ctx.cpp:124
#7  0x00000000012eeb65 in zmq::ctx_t::terminate (this=0x61600000f980) at src/ctx.cpp:201
#8  0x00000000012dc711 in zmqpp::context::terminate() ()
#9  0x0000000000485eef in zmqpp::context::~context (this=0x4431188 <zmqpp::actor::actor_pipe_ctx_>, __in_chrg=<optimized out>) at ../../../../trunk/thirdparty/zmqpp4.2.0/include/zmqpp/context.hpp:100
#10 0x00007ffff5538ff8 in __run_exit_handlers (status=0, listp=0x7ffff58c35f8 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true) at exit.c:82
#11 0x00007ffff5539045 in __GI_exit (status=<optimized out>) at exit.c:104
#12 0x00007ffff551f837 in __libc_start_main (main=0x4792c0 <main(int, char**)>, argc=2, argv=0x7fffffffdb58, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdb48) at ../csu/libc-start.c:325
#13 0x00000000004463a9 in _start ()
commented

Fixed in libzmq 4.2.4

@bluca I see some discussion around this mutex issue. However, I'm using the latest stable release zmq 4.2.5 and still see this core stack.

ZMQ: https://github.com/zeromq/libzmq/tree/v4.2.5
OS: Linux

#0 0x4595c6d4 in raise () from /tmp/rtsplus/lib/libc.so.6
#1 0x4595da30 in abort () from /tmp/rtsplus/lib/libc.so.6
#2 0x45ecd488 in zmq::zmq_abort (errmsg_=errmsg_@entry=0x45a4efc4 "Invalid argument") at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/err.cpp:91
#3 0x45ee4b9c in lock (this=0x45f2a800 <manage_random(bool)::random_sync>) at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/mutex.hpp:142
#4 scoped_lock_t (mutex_=..., this=) at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/mutex.hpp:180
#5 manage_random (init=init@entry=false) at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/random.cpp:142
#6 0x45ee4e24 in zmq::random_close () at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/random.cpp:167
#7 0x45ec0fbc in zmq::ctx_t::~ctx_t (this=0x2fc60, _in_chrg=) at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/ctx.cpp:124
#8 0x45ec15dc in zmq::ctx_t::terminate (this=this@entry=0x2fc60) at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/ctx.cpp:206
#9 0x45f08600 in zmq_ctx_term (ctx
=0x2fc60) at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/zmq.cpp:152
#10 0x46152dd0 in zctx_destroy (self_p=self_p@entry=0x2ec50) at /usr/src/debug/libczmq/3.0.2-r0.0/git/src/zctx.c:112

Can you please help to debug?

Thank you.

Either use a new enough compiler:

#if __cplusplus >= 201103L                                                     \
  || (defined(__cpp_threadsafe_static_init)                                    \
      && __cpp_threadsafe_static_init >= 200806) 

Or use libsodium

Thank you for the quick response @bluca .

I even tried using libsodium, but it failed here to make a syscall for getrandom.
I'm using Linux kernel 4.1.2 so this syscall should be supported.

Let me know if there is anything else to be installed/updated.

(gdb) bt
Python Exception <type 'exceptions.ImportError'> No module named gdb.frames: 
#0  0x45dee2dc in syscall () from /tmp/rtsplus/lib/libc.so.6
#1  0x462cd70c in _randombytes_linux_getrandom (size=<optimized out>, buf=<optimized out>) at /usr/src/debug/libsodium/1.0.3-r0.0/git/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:144
#2  randombytes_linux_getrandom (buf_=<optimized out>, size=16) at /usr/src/debug/libsodium/1.0.3-r0.0/git/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:161
#3  0x462cd7c8 in randombytes_sysrandom_init () at /usr/src/debug/libsodium/1.0.3-r0.0/git/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:181
#4  randombytes_sysrandom_stir () at /usr/src/debug/libsodium/1.0.3-r0.0/git/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:209
#5  0x462cc950 in sodium_init () at /usr/src/debug/libsodium/1.0.3-r0.0/git/src/libsodium/sodium/core.c:20
#6  0x46344b68 in manage_random (init=true) at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/random.cpp:152
#7  zmq::random_open () at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/random.cpp:162
#8  0x46320e5c in zmq::ctx_t::ctx_t (this=0x35630) at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/ctx.cpp:91
#9  0x46368348 in zmq_ctx_new () at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/zmq.cpp:135
#10 0x463684e4 in zmq_init (io_threads_=1) at /usr/src/debug/libzmq/4.2.5-r0/zeromq-4.2.5/src/zmq.cpp:196
#11 0x463d2b24 in zctx__initialize_underlying (self=0x35128) at /usr/src/debug/libczmq/3.0.2-r0.0/git/src/zctx.c:272
#12 0x463d2bdc in zctx__socket_new (self=0x35128, type=1178414044, type@entry=8) at /usr/src/debug/libczmq/3.0.2-r0.0/git/src/zctx.c:286
#13 0x463d8978 in zsocket_new (ctx=<optimized out>, type=type@entry=8) at /usr/src/debug/libczmq/3.0.2-r0.0/git/src/zsocket.c:34

I have no idea - but try to use your distro's library rather than rebuilding it

@bluca
I use the below config in my bitbake recipe so it should take the distro's libsodium version only.
PACKAGECONFIG ??= "libsodium"
PACKAGECONFIG[libsodium] = "--with-libsodium, --without-libsodium, libsodium"

Anyways, I'm looking around for ways to resolve it.
Appreciate your help. :)