[zeromq-dev] Question about zmq_socket_monitor()

Luca Boccassi luca.boccassi at gmail.com
Wed Dec 12 14:50:09 CET 2018

On Tue, 2018-12-11 at 22:07 +0000, Martin.Belanger at dell.com wrote:
> Hi,
> I'm experimenting with zmq_socket_monitor(). I have a XSUB socket
> that I'm monitoring. The monitoring works fine. I'm just trying to
> understand how I can enable/disable monitoring back-and-forth by
> calling zmq_socket_monitor().
> I tried to enable/disable/re-enable monitoring by invoking
> zmq_socket_monitor() as shown below I get the error "Address already
> in use" on the 3rd invocation.
> 1) zmq_socket_monitor(my_xsub_sock, "inproc://starship-enterprise",
> 2) zmq_socket_monitor(my_xsub_sock, NULL, 0);
> 3) zmq_socket_monitor(my_xsub_sock, "inproc://starship-enterprise",
> I followed the source code for zmq_socket_monitor() to a method
> called zmq::socket_base_t::monitor(). That function eventually calls
> zmq_bind() where I believe the error occurs. 
> 1) The first time zmq_socket_monitor() is called a ZMQ_PAIR socket is
> created (_monitor_socket) and bound to address "inproc://starship-
> enterprise". Note that this socket is created with ZMQ_LINGER=0.
> 2) The second time zmq_socket_monitor() is invoked to disable
> monitoring _monitor_socket is closed and because ZMQ_LINGER=0 it
> should go out of existence right away. Right?
> 3) The third time zmq_socket_monitor() is called I get "Address
> already in use" as if the old socket is still there. How can that be?
> Regards,
> Martin

Without looking with gdb, my best guess is a race: the close is
asynchronous and non-blocking, so the third call might try to re-use
the same endpoint that is still technically in use.
IIRC inproc sockets events are processed from the "connecting" socket's
thread, so try to run something (ie: zmq_getsockopt zmq_events) on the
connecting inproc before the third call and see if that helps.

Kind regards,
Luca Boccassi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20181212/d2e0da6e/attachment.sig>

More information about the zeromq-dev mailing list