Skip to content

Commit 0327d9f

Browse files
committed
Fix RecvStream::is_end_stream(): return true only when END_STREAM is received
Before this change, it returned true on other types of disconnection as well. Fixes hyperium#806
1 parent 848885b commit 0327d9f

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/proto/streams/recv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl Recv {
557557
}
558558

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

src/proto/streams/state.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,8 @@ impl State {
413413
matches!(self.inner, Closed(_))
414414
}
415415

416-
pub fn is_recv_closed(&self) -> bool {
417-
matches!(
418-
self.inner,
419-
Closed(..) | HalfClosedRemote(..) | ReservedLocal
420-
)
416+
pub fn is_end_stream(&self) -> bool {
417+
matches!(self.inner, Closed(Cause::EndStream))
421418
}
422419

423420
pub fn is_send_closed(&self) -> bool {

tests/h2-support/src/util.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use bytes::{BufMut, Bytes};
22
use futures::ready;
3+
use std::borrow::BorrowMut;
34
use std::future::Future;
45
use std::pin::Pin;
56
use std::task::{Context, Poll};
@@ -8,7 +9,8 @@ pub fn byte_str(s: &str) -> h2::frame::BytesStr {
89
h2::frame::BytesStr::try_from(Bytes::copy_from_slice(s.as_bytes())).unwrap()
910
}
1011

11-
pub async fn concat(mut body: h2::RecvStream) -> Result<Bytes, h2::Error> {
12+
pub async fn concat<B: BorrowMut<h2::RecvStream>>(mut body: B) -> Result<Bytes, h2::Error> {
13+
let body = body.borrow_mut();
1214
let mut vec = Vec::new();
1315
while let Some(chunk) = body.data().await {
1416
vec.put(chunk?);

tests/h2-tests/tests/stream_states.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,14 @@ async fn errors_if_recv_frame_exceeds_max_frame_size() {
338338
let req = async move {
339339
let resp = client.get("https://example.com/").await.expect("response");
340340
assert_eq!(resp.status(), StatusCode::OK);
341-
let body = resp.into_parts().1;
342-
let res = util::concat(body).await;
341+
let mut body = resp.into_parts().1;
342+
let res = util::concat(&mut body).await;
343343
let err = res.unwrap_err();
344344
assert_eq!(
345345
err.to_string(),
346346
"connection error detected: frame with invalid size"
347347
);
348+
assert!(!body.is_end_stream());
348349
};
349350

350351
// client should see a conn error

0 commit comments

Comments
 (0)