Skip to content

Commit

Permalink
Fix RecvStream::is_end_stream(): return true only when END_STREAM is …
Browse files Browse the repository at this point in the history
…received

Before this change, it returned true on other types of disconnection as
well.

Fixes #806
  • Loading branch information
eaufavor committed Nov 4, 2024
1 parent 848885b commit 0327d9f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/proto/streams/recv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ impl Recv {
}

pub fn is_end_stream(&self, stream: &store::Ptr) -> bool {
if !stream.state.is_recv_closed() {
if !stream.state.is_end_stream() {
return false;
}

Expand Down
7 changes: 2 additions & 5 deletions src/proto/streams/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,8 @@ impl State {
matches!(self.inner, Closed(_))
}

pub fn is_recv_closed(&self) -> bool {
matches!(
self.inner,
Closed(..) | HalfClosedRemote(..) | ReservedLocal
)
pub fn is_end_stream(&self) -> bool {
matches!(self.inner, Closed(Cause::EndStream))
}

pub fn is_send_closed(&self) -> bool {
Expand Down
4 changes: 3 additions & 1 deletion tests/h2-support/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bytes::{BufMut, Bytes};
use futures::ready;
use std::borrow::BorrowMut;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
Expand All @@ -8,7 +9,8 @@ pub fn byte_str(s: &str) -> h2::frame::BytesStr {
h2::frame::BytesStr::try_from(Bytes::copy_from_slice(s.as_bytes())).unwrap()
}

pub async fn concat(mut body: h2::RecvStream) -> Result<Bytes, h2::Error> {
pub async fn concat<B: BorrowMut<h2::RecvStream>>(mut body: B) -> Result<Bytes, h2::Error> {
let body = body.borrow_mut();
let mut vec = Vec::new();
while let Some(chunk) = body.data().await {
vec.put(chunk?);
Expand Down
5 changes: 3 additions & 2 deletions tests/h2-tests/tests/stream_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,14 @@ async fn errors_if_recv_frame_exceeds_max_frame_size() {
let req = async move {
let resp = client.get("https://example.com/").await.expect("response");
assert_eq!(resp.status(), StatusCode::OK);
let body = resp.into_parts().1;
let res = util::concat(body).await;
let mut body = resp.into_parts().1;
let res = util::concat(&mut body).await;
let err = res.unwrap_err();
assert_eq!(
err.to_string(),
"connection error detected: frame with invalid size"
);
assert!(!body.is_end_stream());
};

// client should see a conn error
Expand Down

0 comments on commit 0327d9f

Please sign in to comment.