[zeromq-dev] "too many open files" error in zmq/jzmq

Igor 'Lo' (И.L.) bombsiteunrested at gmail.com
Fri Sep 9 00:02:16 CEST 2011


Hi all.

What can cause an REQ/REP pair to crash (after doing multiple requests
from Java to C++, crashing both sides at random choice) with following
message:

Too many open files
rc == 0 (mailbox.cpp:375)
(END)

C++ side:

        zmq::context_t context (1);
        zmq::socket_t socket (context, ZMQ_REP);
        socket.bind ("tcp:://localhost:1234);

        while (true) {
                void *context = zmq_init(1);
                zmq::message_t *request = new zmq::message_t;
                socket.recv (request);
... // parse request, prepare reply: unsigned char data with length dsize
                zmq::message_t reply (dsize+1);
                memcpy((void *)reply.data(), &data, dsize);
                memset((void *)reply.data()+dsize, '\0', 1);
                socket.send(reply);
       }

Java side:

            ZMQ.Context context = ZMQ.context(1);
            ZMQ.Socket jsocket = context.socket(ZMQ.REQ);
             jsocket.connect ("tcp://localhost:1234");
             jsocket.send(req, 0);
            ZMQ.Poller it = context.poller(1);
            it.setTimeout(2*1000000);
            it.register(jsocket, ZMQ.Poller.POLLIN);
            if (it.pollin(0)) {
             byte[] reply = jsocket.recv(0);
... // parse reply
            }
            jsocket.close();

Java can call the above code from multiple threads.
I suspect the handbook didn't told me how to close used resources in a
correct way.. shouldn't something be done upon zmq::message_t or with
zmq::context? I thought that scope exit at loop should've been
destroying them..

--
cheers,
Igor


More information about the zeromq-dev mailing list