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

Pieter Hintjens ph at imatix.com
Sat Feb 12 16:04:00 CET 2011


Hi Aaron,

In a realistic case you would want to use zmq_poll() to check for
input on the ZMQ_REQ socket before reading.

Further, you'd want some mechanism for detecting server failure and
resending. We've written a small client/server framework for this in
ZFL, which you can use as a design reference or in your C/C++
applications. It's in

https://github.com/zeromq/zfl/blob/master/src/zfl_rpc.c
and
https://github.com/zeromq/zfl/blob/master/src/zfl_rpcd.c

and includes test code that demonstrates how to use these two classes.

-
Pieter Hintjens
iMatix

On Sat, Feb 12, 2011 at 3:55 PM, Aaron Riekenberg
<aaron.riekenberg at gmail.com> wrote:
> 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
> done?
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>



More information about the zeromq-dev mailing list