[zeromq-dev] exception from recv()

Tom Wilberding tom at wilberding.com
Wed Sep 26 18:46:48 CEST 2012


Hi All,

We upgraded from 2.0.10 to 2.2.0 just because it seemed like it would be
a recompile for our code. We ran a 2.2.0 client against a 2.0.10 source
(TCP PUB/SUB) just to confirm that they were wire format compatible. 

Things ran fine for hours with thousands of messages per minute until we
saw the following exception.

> terminate called after throwing an instance of 'zmq::error_t'
>   what():  Interrupted system call

We restarted in the debugger and ran until it happened again and from
the stack trace it was coming from line 336 of zmq.hpp

> inline bool recv (message_t *msg_, int flags_ = 0)
>         {
>             int rc = zmq_recv (ptr, msg_, flags_);
>             if (rc == 0)
>                 return true;
>             if (rc == -1 && zmq_errno () == EAGAIN)
>                 return false;
>             throw error_t ();
>         }

Looking at the release notes:

> * Blocking calls now return EINTR if interrupted by the delivery of a
>   signal; this also means that language bindings which previously had
>   problems with handling SIGINT/^C should now work correctly.

What is the best practice for handling this in C++? The zmq.hpp wrapper
is throwing without any additional info when zmq_recv() returns -1 and
errno is EINTR, so should my app be catching this exception? And if so,
shouldn't information pertaining to the root cause of the interrupt be
passed along?

Or should I be using the API in a different way so that I would not
normally encounter this exception?

My client code is very straightforward:

> //  Prepare our context and socket
>     zmq::context_t context (1);
>     zmq::socket_t socket (context, ZMQ_SUB);
>     std::string url = getSubUrl();
>     socket.connect(url.c_str());
>     socket.setsockopt(ZMQ_SUBSCRIBE, "", 0);
> 
>     while (true) {
>         zmq::message_t message;
> 
>         //  Wait for next request from pub
>         socket.recv(&message);
> 
>         /* print some stuff out */
>     }


Thanks,
Tom





More information about the zeromq-dev mailing list