Fix potential hang if extensions contain same StreamRef

If a user stored a `StreamRef` to the same stream in the request or
response extensions, they would be dropped while the internal store lock
was held. That would lead to a deadlock, since dropping a stream ref
will try to take the store lock to clean up.

Clear extensions of Request and Response before locking store, prevent
this.

Fixes hyperium/hyper#2621
This commit is contained in:
Sean McArthur
2021-08-20 14:30:49 -07:00
parent 288a5f086f
commit ab6f148ee1
2 changed files with 47 additions and 3 deletions

View File

@@ -1059,3 +1059,37 @@ async fn request_without_authority() {
join(client, srv).await;
}
#[tokio::test]
async fn serve_when_request_in_response_extensions() {
h2_support::trace_init!();
let (io, mut client) = mock::new();
let client = async move {
let settings = client.assert_server_handshake().await;
assert_default_settings!(settings);
client
.send_frame(
frames::headers(1)
.request("GET", "https://example.com/")
.eos(),
)
.await;
client
.recv_frame(frames::headers(1).response(200).eos())
.await;
};
let srv = async move {
let mut srv = server::handshake(io).await.expect("handshake");
let (req, mut stream) = srv.next().await.unwrap().unwrap();
let mut rsp = http::Response::new(());
rsp.extensions_mut().insert(req);
stream.send_response(rsp, true).unwrap();
assert!(srv.next().await.is_none());
};
join(client, srv).await;
}