[zeromq-dev] Assertion failure in mailbox.cpp

Jon Gjengset jon at thesquareplanet.com
Mon May 19 15:46:43 CEST 2014

> > > Nevertheless, my application will sometimes (although not always),
> > > crash with an assertion failure at mailbox.cpp:82:
> > 
> > It might be worth noting that I have only ever observed the crash during
> > the shutdown procedure after the second stage has closed its outgoing
> > socket.
> I can see in your code example that you are joining the threads before
> terminating the context, so I wonder if there is still some thread
> safety issue with closing different sockets simultaneously on other
> threads.


It was precisely because I thought closing the context before all
sockets are closed could be a problem that I explicitly join all the
stage threads before terminating the context. In my application, the
main thread never even gets around to destroying the context though, so
I don't think that's where the issue lies.

> In the rbczmq gem, I decided to put a mutex around any calls to close
> a socket so only one could happen at a time. This incurs a performance
> hit for applications opening and closing many sockets - but I
> understand that is not a recommended usage pattern.

If there is a race condition between the closing of different sockets
belonging to the same context, then this should be documented, and
potentially fixed. While I could add a mutex around the closing as you
say, I'd really rather not; part of the reason I wanted to move to ØMQ
in the first place was to get rid of unnecessary locks.

Given that I haven't found anyone else encountering this particular
problem though, it seems unlikely that this is as simple as a race
condition on related sockets when using multiple threads. Presumably
this is a fairly common pattern for ØMQ applications?


More information about the zeromq-dev mailing list