ZMQ : Hanging at Context Termination

If you use ZMQ, and am wondering why you are experiencing hanging when when you exit the program, it’s because the default LINGER value for your socket is set at infinity. When closing the context, the program hangs at the context termination routines.

You need to do this.

// Configure socket to not wait at close time
int linger = 0;
yoursocket->setsockopt (ZMQ_LINGER, &linger, sizeof (linger));

Otherwise, you might run into cases where the context termination routine is waiting for the socket to close. The socket will be blocking still at a function say, socket.recv() and will be unable to unblock unless ZMQ_LINGER is set to 0.

NOTE: Bindings such as CZMQ may have already done this for you.


One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s