[zeromq-dev] [PATCH] Improved response to socket violations

Martin Sustrik sustrik at 250bpm.com
Sat May 21 08:04:47 CEST 2011


On 05/21/2011 01:17 AM, Pieter Hintjens wrote:
> On Fri, May 20, 2011 at 6:58 PM, Martin Sustrik<sustrik at 250bpm.com>  wrote:
>
>> However, this doesn't work if one thread closes the socket and other
>> thread tries to access it afterwards.
>
> Indeed, and this particular scenario is the one that causes this
> assert in mailbox.cpp.
>
> People do also try to actively recv/send from the same socket in
> multiple threads but less often, by experience. However, trying to
> close all sockets from one place seems a regular thing. I've hit
> exactly the same fault myself trying to manage sockets automatically
> in czmq.
>
> Anyone else have an opinion on handling these asserts more "nicely"?

One option is to set socket 'tag' to 0xdeadbeef immediately when 
zmq_close() is called rather then when socket is actually deallocated. 
That would make it fail fast in some scenarios, however, it won't help 
in Mike's scenario where he closes the socket while another thread is 
stuck inside a blocking function on that socket.

The piece of documentation that confused him was actually in the guide 
("Making a clean exit" chapter):

"When you exit the program, close your sockets and then call 
zmq_term(3). This destroys the context."

Btw, he volunteered to provide a more clear version of the text.

Martin



More information about the zeromq-dev mailing list