[zeromq-dev] Questions about socket errors

Martin Lucina mato at kotelna.sk
Wed Feb 10 23:32:38 CET 2010

Hi Brian,

ellisonbg at gmail.com said:
> I am starting to look at using the Python interface to zeromq and have
> some questions about error handling.
> In particular, I am wondering how socket related errors are handled in
> Python.  Some examples of what I saw:
> * If I do s.connect to an endpoint that doesn't exist, it returns
> happily as though it were fine.
> * If I do a recv/send to an endpoint that lost its connection, it
> hangs or returns happliy (NOBLOCK).
> I am guessing that this behavior is unique to the Python bindings.  So

Actually, this behaviour is normal and is not unique to the Python

Calling zmq_connect() (which is what s.connect() does) just means "please
try to connect asynchronously, now or later". You will only get an error if
the endpoint is *invalid* (e.g. Host doesn't resolve, etc.), not if the
other end is not present.

Same goes for recv/send -- 0MQ does autoreconnect and both recv/send are
entirely asynchronous. So if the other end goes away your data will get
sent once it comes back.

We realise that there are many use cases where people do want to know if
a peer is present at least for those transports where it makes sense but
the implications of doing this properly (which means e.g. synchronous
zmq_send() which defeats queueing and batching, etc.) need more thought.

I would suggest implementing a "ping" function at the application level.
Send a message every X seconds and if you don't get a reply within Y
seconds then take evasive action.

Oh, and yes, this needs to be explained much better in the documentation.
I'm working on that...



More information about the zeromq-dev mailing list