[zeromq-dev] Connect with inproc
Chuck Remes
lists at chuckremes.com
Wed Jul 25 18:45:11 CEST 2012
On Jul 25, 2012, at 11:11 AM, Marc Rossi wrote:
>
> Linux w/ ZMQ 2.2.0
>
> I have a publish function that is called from a thread. This publish
> function connects an inproc socket with a socket in another thread.
> Since inproc sockets error on a connect call if the other side isn't
> setup yet I have the publish functino return without publishing
> until the connection can be succesfully established.
>
> This function publishes a high volume of data and sometimes when the
> other side of the socket takes a second or two to setup I run into
> the assertion
>
> Too many open files (signaler.cpp:330)
>
> when it tries to create a socketpair. Can't find where the socketpair
> gets cleaned up after deletion.
>
> Am I missing something with my approach? Initially tried to reuse
> created socket instead of deleting/recreating every time but
> connect would never succeed.
>
Unless there is some delay between attempts, you are probably trying to create and connect that socket hundreds or thousands of times per second until the other thread has completed its setup and called zmq_bind() on the inproc transport.
Socket deletion, like everything else in zeromq, is asynchronous. So, while you may have deleted the socket it does not mean that its resources have been reclaimed yet. In a tight enough loop you will run out of file descriptors because the "deleted" sockets are still holding on to unreleased file descriptors while they await their termination.
I suggest using a real signaling mechanism (like a condition variable) to indicate that your receiver thread has completed its setup. Only then should you try and create the publish socket and connect it.
cr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120725/5908cd4a/attachment.htm>
More information about the zeromq-dev
mailing list