Skip to content
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 RecvStream::is_end_stream(): return true only when END_STREAM is received #810

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_recv_end_stream() {
return false;
}

Expand Down
12 changes: 5 additions & 7 deletions src/proto/streams/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've given this some thought, and I'm less sure that we want the check to be so strict. If it is half-closed successfully, I think we do want to say that the RecvStream is finished. If there is later an error on the sending side, I don't think that should be a problem, the SendStream will notice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Updated to check both Closed(Cause::EndStream) and HalfClosedRemote(..). Also updated the function name accordingly.

)
pub fn is_closed(&self) -> bool {
matches!(self.inner, Closed(_))
}

pub fn is_send_closed(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion tests/h2-tests/tests/flow_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down