[zeromq-dev] Ruby binding (rbzmq) : tracking sockets

Benoît Larroque benoit.larroque at feedbooks.com
Tue Oct 18 14:30:46 CEST 2011


Hello,

First let me state that I am quite new to zeromq. I started less than
a month ago by reading the excellent zguide and played a bit with
zeromq using ruby.

I wanted to get my rails application to communicate with a service
over zmq. When I first tried to hack around, I found that sometimes
the rails server would just hang, not responding to any http request
anymore. Digging a bit into the matter I found that ruby seemed to be
waiting on zmq_term. At that point I recalled reading a relevant
passage in the zguide :

"""By contrast, in 2.0, it was safe to call zmq_term(3) even if there
were open sockets. In 2.1, this is not safe, and it can cause zmq_term
to block. So in 2.1 we always close every socket, before exiting.
Furthermore, if you have any outgoing messages or connects waiting on
a socket, 2.1 will by default wait forever trying to deliver these.
You must set the LINGER socket option (e.g. to zero), on every socket
which may still be busy, before calling zmq_term:"""

I dived into rbzmq[1] and it seems that context_free( which would call
zmq_term) could be called before socket_free (which would call
zmq_close) thus having everything hang when ruby is garbage
collecting.

I have tried to get around this issue by tracking the open sockets
with a list in the gem. Here is my current solution :

https://github.com/zetaben/rbzmq

Before creating a pull request with those changes, I'd like to get
your thoughts about this issue and changes. I'm not even sure about my
diagnostic of the issue and even less sure about the reliability of
those changes (I have not really tried to use the select mechanism)...

Many thanks for this great project.

Best regards,

Benoit Larroque
Feedbooks R&D engineer


[1] https://github.com/zeromq/rbzmq



More information about the zeromq-dev mailing list