I’m using zeromq and storing per thread copies of zeromq sockets in a
class variable. Same technique used by us and others without any
issues.
Here is the code:
def self.client
unless self.clients[Thread.current.object_id]
s = Offbeat::Zmq::IPCTX.socket(ZMQ::PUSH)
s.connect(“inproc://rsyslog”)
self.clients[Thread.current.object_id] = s
end
self.clients[Thread.current.object_id]
end
When I call client, and try to send a message on the socket, it just
hangs the app. The guy who created the em-zeromq gem reported the
same problem with zeromq contexts, he had to define the context
outside of the EM.run block when using eventmachine or it would do the
same thing. He thought it was being garbage collected. Fyi I’m
pretty sure he saw this same behavior on Cruby also.
Now, when I just create the socket within the thread, and don’t stick
it in a class variable, it works fine. However I’m using rails so I
really can’t do that, I need somewhere to hold per thread socket
instances.
I’m rather stumped on this. Anyone have any ideas?
Chris