[zeromq-dev] Lazy Pirate problems.

Balázs Varga bb.varga at gmail.com
Mon Dec 24 00:15:58 CET 2012


Hi,

While I was having a closer look at Lazy Pirate, I may found a bug in the
zmqlib. When the lpserver simulates a server crash, than the  lpclient
tries to reconnect three times. But because the socket just sent a message,
closes the socket, and creates a new one... After the third attempt gives
up, and terminates. Here's the problem, the zmq_term() will block forever
sometimes, if I put a sleep after zmq_close() than It seems like the
context always terminates.

Just made a little test case, which reproduce this on my machine (win7
32bit, zmq 3.2.2), what do you think?

#include "../include/zmq.h"
#include "../include/zmq_utils.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main (int argc, char *argv [])
{
    void *ctx;
    void *s;
    void *ser;
    int rc;
    zmq_msg_t msg;

    printf("Merry Christmas\n");

while (true) {
 ctx = zmq_init (1);
if (!ctx) {
printf ("error in zmq_init: %s\n", zmq_strerror (errno));
 return -1;
}

ser = zmq_socket (ctx, ZMQ_REP);
 rc = zmq_bind (ser, "tcp://*:5555");
if (rc != 0) {
printf ("error in zmq_bind: %s\n", zmq_strerror (errno));
 return -1;
}

printf("create REQ socket\n");
 s = zmq_socket (ctx, ZMQ_REQ);
if (!s) {
printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
 return -1;
}

rc = zmq_connect (s, "tcp://localhost:5555");
 if (rc != 0) {
printf ("error in zmq_connect: %s\n", zmq_strerror (errno));
 return -1;
}

rc = zmq_msg_init_size (&msg, 5);
 if (rc != 0) {
printf ("error in zmq_msg_init_size: %s\n", zmq_strerror (errno));
 return -1;
}
memset (zmq_msg_data (&msg), 0, 5);

zmq_sendmsg(s,&msg, 0);
rc = zmq_msg_close (&msg);
 printf("closing REQ socket\n");
zmq_close(s);
//zmq_sleep(1);

printf("create REQ socket\n");
s = zmq_socket (ctx, ZMQ_REQ);
 if (!s) {
printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
 return -1;
}

rc = zmq_connect (s, "tcp://localhost:5555");
 if (rc != 0) {
printf ("error in zmq_connect: %s\n", zmq_strerror (errno));
 return -1;
}

rc = zmq_msg_init_size (&msg, 5);
 if (rc != 0) {
printf ("error in zmq_msg_init_size: %s\n", zmq_strerror (errno));
 return -1;
}
memset (zmq_msg_data (&msg), 0, 5);

zmq_sendmsg(s,&msg, 0);
rc = zmq_msg_close (&msg);
 printf("closing REQ socket\n");
zmq_close(s);
//zmq_sleep(1);

printf("closing REP socket\n");
zmq_close(ser);

printf("Terminating context\n");
zmq_term( ctx );
printf("done...\n");
 }
    return 0;
}


Merry Christmas

balazs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20121224/82634301/attachment.htm>


More information about the zeromq-dev mailing list