-
Notifications
You must be signed in to change notification settings - Fork 50
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
fix(client): drop connection if body of a response was not consumed, to avoid bad state #1177
Conversation
Not sure this is best way, but at least it's safer, i'm not sure how to consume the body if dropped so for the moment i destroy the connection in this case. I think it will require a specific state of the connection so it will ready the previous body before the next request in this case, but maybe you will have a better feedback for this. |
f2c8bfc
to
ad51cce
Compare
ad51cce
to
8a82b9d
Compare
I believe using In xitca-web/http/src/h1/proto/codec.rs Line 252 in 99f7c97
As for body with impl<C> Stream for ResponseBody<C> {
type Item = Result<Bytes, BodyError>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let this = self.get_mut();
loop {
match this.decoder.decode(&mut this.buf) {
ChunkResult::OnEof => {
// this does not really impact the state of TransferCoding other than hint who polling the ResponseBody should not skip the OnEof state.
},
}
}
}
} |
There could be edge case where user weirdly decide to ignore body state and stop polling the stream when OnEof state appear. But I personally don't believe this is case we should burden ourselves to support. The worst case is connection can be closed prematurely due to user not polling body until it reaches None state. |
8a82b9d
to
ca11fca
Compare
I updated the PR to use |
Sorry I forgot to mention that it could be better to impl the Drop on |
It's not possible to drop it on |
Yea it's Ok to remove generic type from the |
66531d8
to
c4712ec
Compare
Should be good then, clippy failure seems unrelated |
c4712ec
to
b5ac294
Compare
Looks good |
Pr is not finished, i only added a test.
Actually if a body is not readed on the client, but the reponse is dropped, conn will go back to the pool with existing data of the response not consumed, which will fail the next request since it will try to decode the header on the previous response body
This may happens if a client send a request, gets an error with a status code and a message in the body by example, and when there is a specific status code (in this case the error), will not bother to consume the body.
Not sure how to handle this well, i assume we should force the body to be consumed before going back to the pool but i'm not sure how to do this