-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to handle closing sockets? #31
Comments
This turns out to be even more insidious. We need to handle closing the waker socket as well. |
Turns out, fixing the waker issue was trivial. Also sent celluloid/celluloid#376, which is related. |
It turns out that this is especially problematic if we forcefully kill an actor, since finalizers might not be run, it seems. I added a global registry for sockets in jnicklas/celluloid-jeromq in this commit, because I couldn't get the test suite to even run reliably otherwise. Even with this change added, I think that people should definitely add finalizers to close sockets to their actors. This is just a last line of defence. So my suggestion for fixing this issue in other words is to do both (1) and (2) ;). If you agree, I'll port the change from celluloid-jeromq, and I'll update the documentation. |
@jnicklas you need finalizers to close open sockets. That's the only option |
@tarcieri I agree. The registry I added in celluloid-jeromq isn't meant as a replacement for closing sockets in finalizers, it's meant as a last line of defence in case the actor thread is forcefully killed via |
On the other hand, maybe in that case it's warranted that the process needs to be |
in the |
I don't follow. I know it doesn't matter when the app is So we either never call Not calling |
I'm in the process of writing a few specs for this gem. I ran into a problem which I wanted to get some feedback on. In order to separate tests more cleanly from each other, I wrapped all tests in an around filter which calls
Celluloid::ZMQ.init
before andCelluloid::ZMQ.terminate
afterwards, so it sets up a clean ZMQ context for each test. This seems to work nicely, except thatzmq_term
hangs indefinitely until all sockets created within the context are explicitly closed. This means that every socket we create, we need to explicitly close.The way I see it, there are two ways of handling this:
Simply update the documentation. Leave it up to the user to make sure they call
socket.close
in a finalizer.Keep track of all sockets created within an actor and add a finalizer to Celluloid::ZMQ which closes them automatically.
While (2) is more user friendly, it could also be problematic, since Celluloid can only have one finalizer per actor (why, btw?), if the user ever adds their own finalizer to the actor, they would overwrite the built in finalizer and mess up the sockets getting closed. So in a way, I think (1) is the better solution at this point.
What do you think?
The text was updated successfully, but these errors were encountered: