[zeromq-dev] zmq_socket_monitor blocks port of REP/REQ TCP/IP in C

Björn Kuhlbrodt bjoern.kuhlbrodt at gpsolar.com
Thu Jan 23 10:02:17 CET 2014

>No offence taken, sorry if I seemed rude. What I meant to say was, it's user-built software, so if you have suggestions for >improvements, the right way to make them is via patches.

Excellent and agreed. 

In the meantime I found the problem by debugging into the ZMQ sources. I'll describe the problem here, and a workaround just to make sure that this threads ends with a solution.

1. The problem: 
	- when closing the context, the tcp_listeners go into tcp_listener_t::process_term
	- which calls a tcp_listener_t::close
	- which sends a socket->event_closed (endpoint, s);
	- which calls socket_base_t::monitor_event
	- which executes if (monitor_socket)
	In the meantime, someone (the reaper?) sends STOP for the monitor sockets
	- which calls socket_base_t::process_stop
	- which calls socket_base_t::stop_monitor()
	- which closes the monitor_socket
	- end sets monitor_socket = NULL

I can see that monitor_socket is != NULL when I enter socket_base_t::monitor_event, but NULL when it crashes. I.e. we have a race condition between _ctx_term sending and event_closed and the shutting down of the monitor socket.

2. Workaround:

There is an undocumented feature in socket_base_t::monitor:

    // Support deregistering monitoring endpoints as well
    if (addr_ == NULL) {
        stop_monitor ();
        return 0;

So I call 

rc = zmq_socket_monitor(m_pZReceiveSocket, NULL, ZMQ_EVENT_ALL);

	- which calls socket_base_t::monitor
	- which calls stop_monitor ();
	- which closes the monitor and sets monitor_socket = NULL
	- So later (few ms really) when ctx_term comes to work:
	- monitor_socket == NULL and _base_t::monitor_event does no try to send an event with the dying monitor

3. Solution

zmq_disconnect should also call stop_monitor. I'll try to make a patch, but it'll take some time.

Best regards

Dr. Björn Kuhlbrodt
Senior Software Developer
GP Inspect GmbH

Tel: +49 89 750778 4729 
Fax: +49 89 750778 4710 
Mail: bjoern.kuhlbrodt at gpsolar.com

GP Inspect GmbH | Hainbuchenring 9-11 | 82061 Neuried | Deutschland
Geschäftsführer | Christian Probst, Dr. Eric Rüland, Enis Ersü, Martin Heinrich
Amtsgericht München | HRB 173887

A company of ISRA VISION Group

This e-mail may contain material that is confidential, privileged and for the sole use of the intended recipient. Any review, reliance or
distribution by others or forwarding without express permission is strictly prohibited. If you are not the intended recipient, please
contact the sender and delete all copies. GP Inspect GmbH, ISRA VISION AG, its branches and subsidiaries herewith exclude
any liability for third-party information recognizably contained in this email or its attachments. Third-party information does not
necessarily reflect the opinion of GP Inspect GmbH or ISRA VISION AG.


-----Original Message-----
From: zeromq-dev-bounces at lists.zeromq.org [mailto:zeromq-dev-bounces at lists.zeromq.org] On Behalf Of Pieter Hintjens
Sent: Mittwoch, 22. Januar 2014 20:40
To: ZeroMQ development list
Subject: Re: [zeromq-dev] zmq_socket_monitor blocks port of REP/REQ TCP/IP in C

On Wed, Jan 22, 2014 at 4:00 AM, Björn Kuhlbrodt <bjoern.kuhlbrodt at gpsolar.com> wrote:

> No offence meant. I appreciate your work and being a developer myself can full-heartedly understand that 'Hey that free stuff isn't working'-mails are not welcome.

No offence taken, sorry if I seemed rude. What I meant to say was, it's user-built software, so if you have suggestions for improvements, the right way to make them is via patches.

zeromq-dev mailing list
zeromq-dev at lists.zeromq.org

More information about the zeromq-dev mailing list