[zeromq-dev] ZMQ_REQ/ZMQ_REP - what happens if the server fails during a request?

Aaron Riekenberg aaron.riekenberg at gmail.com
Sat Feb 12 15:55:58 CET 2011

I have a client that creates a ZMQ_REQ socket, calls send() to send a
request to a server, then calls recv() to receive the response.

The server creates a ZMQ_REP socket, calls recv() to receive a
request, then calls send() to send a response back to the client.

Suppose the server dies after it receives a request but before it
sends a response back.  I'm finding that this causes the client to
block forever waiting on the recv() call that should receive the
response.  Even if the server is restarted the client is still stuck,
since the server will never again receive this request.

This seems like a problem any realistic application using REQ/REP will
have to deal with, so I'm wondering what the suggested way to deal
with this is.  One option might be to use zmq_poll in the client with
a timeout to see if the server sends a response within some timeout
period.  This has its own issues, since the zmq_poll man page says it
may return before the timeout elapses.  So I suppose I could write a
loop calling zmq_poll and checking the clock to see if the timeout has
really elapsed, but this is getting ugly.

It seems a much more elegant solution would be for the recv() call on
the ZMQ_REQ socket in the client to return some error code if the
connection to the server is broken.  Is there a reason this wasn't

More information about the zeromq-dev mailing list