-
Notifications
You must be signed in to change notification settings - Fork 189
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
Document how to close sockets in a threaded scenario #545
Comments
Note: Experimentally, async exceptions seem to be delivered to blocked threads. This is on arch linux + nix with these package versions:
|
We implemented a way to use duplex connections in IOG, although in a more complex scenario. We have a component which tracks state of the connection, e.g. in which direction it is being used. We do it at the protocol level (communication protocol which we implemented), while for taking care of socket we simply use What I would do is implement a simple protocol which has a termination message, then in the |
Usually, @voidus You are using UNIX-domain sockets. I don't understand why socket-specific is not a good solution. |
@coot I'd rather not depend on the connecting applications being well-behaved on both ends. @kazu-yamamoto I'm not sure what you mean with socket-specific. I tried to search for it but couldn't find anything really. |
You said "but that seems like a worse solution because it is socket-specific" in the first comment. I would like to know why you think so. |
When thread A calls |
Honestly, looking back, I'd say it's because I'm writing a lot of python and have no hesitation to use exceptions for control flow. The other reason why I thought it would be better is that it's applicable in other situations as well, so it felt like a more general solution. I'll prepare a PR for brief documentation changes that would have helped me. |
Heya,
Disclaimer: I'm still figuring this stuff out, so it might be obvious for some of you. That would actually be cool, because then documenting it should be easy :)
I think we should document a recommended way to interrupt threads that are blocking on a
recv
call.Motivating context
I want to build a small tool that listens to a unix socket, connects to another one and forwards data in both directions. I've decided to have one thread per direction, i.e.
downstream
recv
s from the connection made to us and writes to the one we connect to, whileupstream
does the same thing but with the sockets flipped.The situation I'm struggling with is that one of the connections is closed by the other end. (Since it's basically symmetrical at this point, I think we can consider them in one go). I obviously want the tool to be a good citizen, so the other socket should be gracefully closed immediately.
As far as I can tell, there's no way to wait for
recv
or something else, so the only thing I can do is usethrowTo
to interrupt the thread, right? (And then close the socket in an appropriate exception handler)So I was looking for something in the documentation that tells me whether asynchronous exceptions are delivered while blocking on
recv
but didn't find anything. I've considered usingshutdown
on the socket instead, but that seems like a worse solution because it is socket-specific.It seems to me that all applications that work with multiple sockets in a single context need something like this, so some guidance would be great. Could also be just a link to some existing explanation of course
The text was updated successfully, but these errors were encountered: