libzmq icon indicating copy to clipboard operation
libzmq copied to clipboard

can't destroy context without setting 'ZMQ_LINGER' on each socket to 0

Open ClosetGeek-Git opened this issue 1 year ago • 0 comments

I'm having problems with a application blocking when calling zmq_ctx_destroy (context); . The man page for 'zmq_ctx_destroy' states:

  1. Any blocking operations currently in progress on sockets open within context shall return immediately with an error code of ETERM. With the exception of zmq_close(), any further operations on sockets open within context shall fail with an error code of ETERM.
  2. After interrupting all blocking calls, zmq_ctx_destroy() shall block until the following conditions are satisfied:
  • All sockets open within context have been closed with zmq_close().
  • For each socket within context, all messages sent by the application with zmq_send() have either been physically transferred to a network peer, or the socket's linger period set with the ZMQ_LINGER socket option has expired.

After making sure that all sockets are being closed and still having the problem I went the extent of commenting out all occurrences of s_send and 'zmq_ctx_destroy' still blocks. So I've now had to set 'ZMQ_LINGER' to 0 which results in being able to successfully destroying the socket but still leaves me wondering why. No sockets are sending (commented out), no sockets are reading. I am using a dedicated socket to notify the zmq_poll of the only reader that the application is closing, but when this didn't work I commented out the only read along with the entire zmq_poll routine. It's all being skipped, so I'm left 100% sure that there are no pending calls to send, read, or poll.

Just a general observation, condition 2 states "all messages sent by the application with zmq_send() have either been physically transferred to a network peer" - after commenting out sends that leaves me to wonder if it is from internal sends

Are there any other conditions that will cause this behavior besides those listed in the man page?

ClosetGeek-Git avatar Jul 20 '22 20:07 ClosetGeek-Git