[zeromq-dev] XREQ socket sends messages to death server. How to notice and disconnect from a death server?

Toni Michel michel at snaptec.de
Thu Dec 9 00:58:55 CET 2010

I have a XREQ socket at the client, talking to a set of servers(XREP).
I want to handle server deaths. The client should notice this, as he 
does not get an answer for a sent request in an
appropriate time. In this case, the client should resend the message. As 
he is connected to more than 1 server,
the request will be accomplished by a server which is still available.
=> I cant use blocking recv at the client, as otherwise the client will 
block once he sent a message to a death server
=> instead, the recv must use zmq.NOBLOCK. Each time the client sends a 
message, he waits for 2 seconds max for a reply.
In case he does not get any, he will resend the message.
The client sends a message to a death server. As he does not get any 
reply for 2 seconds, he resends the message. As the
XREQ is loadbalancing, the message is sent to another server, and 
everythings fine. But the problem is, that one of the
next messages will be send to the death server again. Consider having 
one client and 3 servers. If one server dies, the
client is sending a msg to the death server every 3 messages 
=> So every 3 messages the client waits for another 2 seconds. Having a 
Gui behind, this behavior is unacceptable.

I thought ZMQ will notice server deaths and remove kill the connection to such servers automatically.

Here you can find the complete Testcase: https://gist.github.com/734071

I am starting the client first, connecting to the 3 server adresses. Then I start one server, which actually binds to its address.
The client tries to send the messages load-balanced to all 3 servers, although only one has performed a bind. So the client runs
in the timeout and tries to resend the message to another server.

So the main question are:
- Am I misunderstanding something?
- Do I have to disconnect the client from death servers by manually? I thought zmq would handle it?

Thanks for your help.
- Toni

More information about the zeromq-dev mailing list