[zeromq-dev] Router-Router Reconnection Issue

Goswin von Brederlow goswin-v-b at web.de
Thu Jun 5 11:17:34 CEST 2014


On Tue, Jun 03, 2014 at 02:13:12PM -0700, Jeremy Im wrote:
> Hello,
> 
> We're using 0mq to great success, but we've run into a problem in using
> router-router connections; we are using explicit socket identities so that
> we can perform addressing from a single 0mq socket (e.g. on the client, we
> will connect to multiple servers by calling zmq_connect multiple times, and
> put the socket identity of the desired target server). The issue we are
> running into is when the server is taken offline, then brought back online,
> the client can no longer communicate with it.
> 
> The following code snippet reproduces the issue we are seeing:
> https://gist.github.com/anonymous/0758bb155575aeb090cc
> 
>    - Upon the server socket being closed, the client socket enters a
>    reconnect loop
>    - Even if zmq_disconnect is called on the client socket, it remains in
>    the reconnect loop
>    - Upon the server socket being available again, the reconnect loop
>    recreates the connection
>    - A subsequent zmq_connect from the client socket succeeds
>    - When sending a message, no message is received on the server
> 
> If I comment out lines 237 and 245, the server does receive the message
> from the client. However, the monitor output would seem to indicate that
> there's no way to halt the reconnect loop short of closing the client
> socket. Is that the intended behaviour?
> 
> Thanks,
> 
> Jeremy

In ZeroMQ 4.1: man zmq-setsockopt 

  ZMQ_ROUTER_HANDOVER: handle duplicate client identities on ROUTER sockets

  If two clients use the same identity when connecting to a ROUTER, the
  results shall depend on the ZMQ_ROUTER_HANDOVER option setting. If
  that is not set (or set to the default of zero), the ROUTER socket
  shall reject clients trying to connect with an already-used identity.
  If that option is set to 1, the ROUTER socket shall hand-over the
  connection to the new client and disconnect the existing one.

    Option value type	 	int
    Option value unit	 	0, 1
    Default value 		0
    Applicable socket types 	ZMQ_ROUTER

It takes a (long) while for tcp sockets to timeout and die when not
shut down properly. So when the server restarts the old connection
probably still lingers and prevents the new one from working. With
fixed identities you want to enable ZMQ_ROUTER_HANDOVER.

MfG
	Goswin



More information about the zeromq-dev mailing list