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

Ilja Golshtein ilejncs at narod.ru
Fri Sep 9 09:21:10 CEST 2011

Agree with Mikko.

You have another variable of context_t type out of the loop scope.

Besides this request should be deleted.
If you have reasons to create it via new (auto variable seems to be more natural),
use auto_ptr, a kind of smart pointer or just explicit delete.

09.09.2011, 02:27, "Mikko Koppanen" <mikko.koppanen at gmail.com>:
> 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
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Best regards,
Ilja Golshtein.

More information about the zeromq-dev mailing list