Closed qqshfox closed 9 years ago
Some things you can try (just to check where the problem comes from):
I don't see why it might hangs at first glance.
I've already tried.
keep a reference to the context (@ctx instead of ctx)
As I mentioned in the comment, this works.
remove the "p @s"
It won't help.
oops, my bad I missed (or more misread) the comment in your original post xD I am pretty sure the issue is in ffi-rzmq and not in libzmq, I have not dealt directly with ffi for quite some time now but I remember strange bugs when a reference is not kept to each objects.
I think what happens is the context is destroyed when it goes out of scope and since a socket if opened libzmq it will wait on it, most of the issues I had at the time similar to this were only reproduced in examples/tests since in real use case you will often do thing differently, in this case you should keep a reference to the context anyway.
I don't have the code but a way to solve it would be for each socket to keep a reference to the ruby object representing the context.
@qqshfox The information provided by @schmurfy is correct. If you do not keep the 'ctx' around, the garbage collector will collect it and try to terminate the context. Any open sockets will then start to return ETERM. Please read the man pages and documentation for zeromq over at zeromq.org.
The easiest fix for the code above is to change 'ctx' to '@ctx' so it is stored in an instance variable for your class.
zmq newbie here. I'm trying to play zmq with sinatra.
it could print the
@s
, then hanging on there:after
ctrl-c
:Is this intentional in
ffi-rzmq
or even inlibzmq
? Or it just might be a bug that the ruby objectctx
was GCed in that situation?Thanks, Hanfei
PS.