zmq_ctx_term() blocks while sockets closed
Observations:
I had the same problem. Despite the fact that I was closing the socket of ZMQ_REQ
type, and zmq_close()
returned 0
, zmq_ctx_term()
would still block. This was happening only after sending a message to a peer that was not running.
zmq_send()
would return immediately, but zmq_recvmsg()
would time out.
After that I was closing the socket and calling zmq_ctx_term()
. Apparently, despite the fact that zmq_close()
returned 0
, the sent message was still in an outgoing queue, and for that reason zmq_ctx_term()
would block.
Solution:
I solved the problem by setting ZMQ_LINGER
option to half the value of ZMQ_RCVTIMEO
. This behavior is actually described herehttp://api.zeromq.org/4-0:zmq-ctx-term