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

streams: notify recv task upon reset #791

Merged
merged 1 commit into from
Aug 2, 2024
Merged
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
3 changes: 3 additions & 0 deletions src/proto/streams/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ impl Send {

// Transition the state to reset no matter what.
stream.state.set_reset(stream_id, reason, initiator);
// Notify the recv task if it's waiting, because it'll
// want to hear about the reset.
stream.notify_recv();

// If closed AND the send queue is flushed, then the stream cannot be
// reset explicitly, either. Implicit resets can still be queued.
Expand Down
27 changes: 18 additions & 9 deletions tests/h2-tests/tests/client_request.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use futures::future::{join, ready, select, Either};
use futures::future::{join, join_all, ready, select, Either};
use futures::stream::FuturesUnordered;
use futures::StreamExt;
use h2_support::prelude::*;
use std::io;
use std::pin::Pin;
use std::task::Context;
use std::{io, panic};

#[tokio::test]
async fn handshake() {
Expand Down Expand Up @@ -849,7 +849,7 @@ async fn recv_too_big_headers() {
};

let client = async move {
let (mut client, mut conn) = client::Builder::new()
let (mut client, conn) = client::Builder::new()
.max_header_list_size(10)
.handshake::<_, Bytes>(io)
.await
Expand All @@ -861,25 +861,34 @@ async fn recv_too_big_headers() {
.unwrap();

let req1 = client.send_request(request, true);
let req1 = async move {
// Spawn tasks to ensure that the error wakes up tasks that are blocked
// waiting for a response.
let req1 = tokio::spawn(async move {
let err = req1.expect("send_request").0.await.expect_err("response1");
assert_eq!(err.reason(), Some(Reason::REFUSED_STREAM));
};
});

let request = Request::builder()
.uri("https://http2.akamai.com/")
.body(())
.unwrap();

let req2 = client.send_request(request, true);
let req2 = async move {
let req2 = tokio::spawn(async move {
let err = req2.expect("send_request").0.await.expect_err("response2");
assert_eq!(err.reason(), Some(Reason::REFUSED_STREAM));
};
});

conn.drive(join(req1, req2)).await;
conn.await.expect("client");
let conn = tokio::spawn(async move {
conn.await.expect("client");
});
for err in join_all([req1, req2, conn]).await {
if let Some(err) = err.err().and_then(|err| err.try_into_panic().ok()) {
std::panic::resume_unwind(err);
}
}
};

join(srv, client).await;
}

Expand Down