-
Notifications
You must be signed in to change notification settings - Fork 999
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
[request-response] Allow for a way to close the substream #1650
Comments
If you drop the |
I think what I would want is: fn upgrade_inbound(mut self, mut io: NegotiatedSubstream, protocol: Self::Info) -> Self::Future {
async move {
let read = self.codec.read_request(&protocol, &mut io);
let request = read.await?;
if let Ok(()) = self.request_sender.send(request) {
match self.response_receiver.await {
Ok(response) => {
let write = self.codec.write_response(&protocol, &mut io, response);
write.await?;
}
Err(_) => {
io.close().await;
}
}
}
Ok(())
}.boxed()
} If the substream is not explicitely closed, the side waiting for the response will not receive |
Is I will have to experiment with this a bit more but I couldn't get the code to trigger |
Every substream must be |
See also #1660. |
Sorry I should have probably made that more clear! The
I was assuming that this only refers to the substream and not the actual connection though. I will double check if #1660 produces the behaviour I'd want :) |
So I checked with #1660 applied but it unfortunately doesn't give me the result I am anticipating. I've also experimented with a local patch that moves the closing of the substream to the very end of the upgrade, applying it regardless of whether we sent a response or not. Doing so produces the intended behaviour of the sender receiving a I tried to write a test for it within the |
Ok, I think I finally understand the point. If your protocol generally expects responses, as your example does, and you explicitly close the substream without sending a response, the receiving end will encounter a premature EOF when reading the response, and any error in an upgrade other than a timeout results in an error returned by the connection handler that will close the connection. Furthermore, while you can do this right now, you would prefer if this behaviour could be achieved by just dropping the |
Yes, thank you elaborating on it again! I am aware that this kind of error handling is not very nice! Thanks for considering the usecase and applying the suggestion! :) |
Closing the substream in a request-response protocol is a convenient way of signaling an error to the other peer.
Unfortunately, the only way I've been able to achieve that at the moment is by creating a response enum:
https://github.com/comit-network/comit-rs/blob/2cca5fef69b49337279c16f4f7421b8052e4cbd0/comit/src/network/protocols/announce.rs#L352-L374
This has the downside that the sender side has to deal with the enum as well although the response never makes it over the wire.
https://github.com/comit-network/comit-rs/blob/2cca5fef69b49337279c16f4f7421b8052e4cbd0/comit/src/network/protocols/announce.rs#L205-L217
Would it be possible to add an interface to
RequestResponse
that allows to close a substream? Maybe dropping theResponseChannel
could do that automatically?The text was updated successfully, but these errors were encountered: