From 1857605c83eaa719b84d4999f1082e6a89719ed1 Mon Sep 17 00:00:00 2001 From: Yuchen Wu Date: Mon, 4 Nov 2024 08:37:01 -0800 Subject: [PATCH] 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 #806 --- src/proto/streams/recv.rs | 2 +- src/proto/streams/state.rs | 12 +++++------- tests/h2-tests/tests/flow_control.rs | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/proto/streams/recv.rs b/src/proto/streams/recv.rs index a70527e2..46544446 100644 --- a/src/proto/streams/recv.rs +++ b/src/proto/streams/recv.rs @@ -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_recv_end_stream() { return false; } diff --git a/src/proto/streams/state.rs b/src/proto/streams/state.rs index 5256f09c..ed016e06 100644 --- a/src/proto/streams/state.rs +++ b/src/proto/streams/state.rs @@ -409,15 +409,13 @@ impl State { ) } - pub fn is_closed(&self) -> bool { - matches!(self.inner, Closed(_)) + pub fn is_recv_end_stream(&self) -> bool { + // In either case END_STREAM has been received + matches!(self.inner, Closed(Cause::EndStream) | HalfClosedRemote(..)) } - pub fn is_recv_closed(&self) -> bool { - matches!( - self.inner, - Closed(..) | HalfClosedRemote(..) | ReservedLocal - ) + pub fn is_closed(&self) -> bool { + matches!(self.inner, Closed(_)) } pub fn is_send_closed(&self) -> bool { diff --git a/tests/h2-tests/tests/flow_control.rs b/tests/h2-tests/tests/flow_control.rs index e3caaff5..292c303c 100644 --- a/tests/h2-tests/tests/flow_control.rs +++ b/tests/h2-tests/tests/flow_control.rs @@ -1339,7 +1339,7 @@ async fn client_decrease_initial_window_size() { conn.drive(async { data(&mut body5, "body5 data2").await; data(&mut body5, "body5 data3").await; - assert!(body3.is_end_stream()); + assert!(!body3.is_end_stream()); }) .await;