Skip to content

Commit

Permalink
streams: notify recv task upon reset
Browse files Browse the repository at this point in the history
Before this change, the transition to the reset state wouldn't notify
tasks that were waiting for a response. The motivating case for this
patch involved a large header being sent by the server. This case was
mostly tested by an existing test, but because that test did not spawn
separate tasks and kept polling the futures through its use of
`conn.drive`, the missing notify was masked.

Informs hyperium/hyper#3724.
  • Loading branch information
ajwerner committed Aug 2, 2024
1 parent cf95990 commit ecd5144
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
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

0 comments on commit ecd5144

Please sign in to comment.