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

Mikko Koppanen mikko.koppanen at gmail.com
Fri Sep 9 00:27:02 CEST 2011


2011/9/8 Igor 'Lo' (И.L.) <bombsiteunrested at gmail.com>:
> 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);
>       }

Hi,

I notice that you are creating a new context in while loop in the C++
code. Is this intentional? I think each context creates at least one
socket for the internal logging, which would cause it to run out of
handles eventually as these contexts are not closed in that piece of
code. The Java side could run out of file handles if you are rapidly
opening and closing large amounts of sockets. It might be better to
create one socket per thread and use it for a longer period.

-- 
Mikko Koppanen



More information about the zeromq-dev mailing list