[zeromq-dev] signal handling problem report

Sergey Matveychuk sem33 at yandex-team.ru
Sat Dec 17 15:56:24 CET 2011


Hi.

Here: http://zguide.zeromq.org/page:all there is example code for signal 
handling. It works well almost always. But there is a problem with 
ZMQ_SUB. Let's modify code a little (here is just main() function, other 
code see in example at url above):

int main (void)
{
     void *context = zmq_init (1);
     void *socket = zmq_socket (context, ZMQ_SUB);
     zmq_connect (socket, "tcp://some.server.net:5555");
     zmq_setsockopt(socket, ZMQ_SUBSCRIBE, NULL, 0);

     s_catch_signals ();
     while (1) {
         // Blocking read will exit on a signal
         char buf[1024];
         zmq_recv (socket, buf, 1024, 0);

         if (s_interrupted) {
             printf ("W: interrupt received, killing server?\n");
             break;
         }
     }
     zmq_close (socket);
     zmq_term (context);
     return 0;
}

It catches a signal (^C) and hangs in zmq_term() function till you press 
^C again. It happens only when some condition has happened.

This is the condition: some.server.net is exist and nothing listen port 
5555. So the server send RST for every connection.

For all other cases: no server, firewalled port, real publisher listen 
on port 5555, signal handling works as expected.

If you'll remove line zmq_setsockopt(socket, ZMQ_SUBSCRIBE, NULL, 0); 
signal handling works well too.

I've noticed it when my publisher crashed and my subscribers stoped only 
after second ^C.



More information about the zeromq-dev mailing list