[zeromq-dev] PUB/SUB socket result in server's crash

Martin Sustrik sustrik at 250bpm.com
Fri Jul 22 08:46:09 CEST 2011

On 07/22/2011 04:33 AM, yy l wrote:

> But I have closed the socket every time after connecting server. So,
> when client close socket, is it mean that it actively shutdown
> connection, and does server know client's socket closing, and what's
> server's reaction, will it release the resource of machine?

Yes, the server will release associated resources.

The problem in your case are the resources owned by the application thread.

When connection/disconnection happens, I/O thread sends an internal 
message (a.k.a. command) to you thread to notify it about the event. 
Given that your test program never calls libzmq, it has no opportunity 
to process the command. Thus, the command is queued for processing later.

In the long run the queued commands will fill the pipe they are passed 
through (socketpair). In new versions of 0mq, the commands are stored in 
memory rather than in sockepair buffers, which allows for more commands 
to be queued, but given that your application thread never passes 
control to libzmq, it'll fail ultimately once it exhausts all the memory.

The right way to handle this is to have an even loop in the server 
application, say based on zmq_poll, or maybe just doing zmq_recv.


More information about the zeromq-dev mailing list