Hi Balazs, I didn't try the test code yet, but are you sure it's not simply the linger problem? By default zmq_term will block forever in several cases unless you set LINGER to some low interval on all sockets before closing them.
-Pieter On Mon, Dec 24, 2012 at 1:15 AM, Balázs Varga <[email protected]> wrote: > 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 > > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev > _______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
