Skip to content

Commit 75f62f2

Browse files
authored
fix: ensure H3ResponseFuture is sync (#2685)
1 parent 0e1d188 commit 75f62f2

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/async_impl/h3_client/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::future::{self, Future};
1515
use std::pin::Pin;
1616
use std::task::{Context, Poll};
1717
use std::time::Duration;
18+
use sync_wrapper::SyncWrapper;
1819

1920
#[derive(Clone)]
2021
pub(crate) struct H3Client {
@@ -77,24 +78,24 @@ impl H3Client {
7778
Ok(s) => s,
7879
Err(e) => {
7980
return H3ResponseFuture {
80-
inner: Box::pin(future::ready(Err(e))),
81+
inner: SyncWrapper::new(Box::pin(future::ready(Err(e)))),
8182
}
8283
}
8384
};
8485
H3ResponseFuture {
85-
inner: Box::pin(self.clone().send_request(pool_key, req)),
86+
inner: SyncWrapper::new(Box::pin(self.clone().send_request(pool_key, req))),
8687
}
8788
}
8889
}
8990

9091
pub(crate) struct H3ResponseFuture {
91-
inner: Pin<Box<dyn Future<Output = Result<Response<ResponseBody>, Error>> + Send>>,
92+
inner: SyncWrapper<Pin<Box<dyn Future<Output = Result<Response<ResponseBody>, Error>> + Send>>>,
9293
}
9394

9495
impl Future for H3ResponseFuture {
9596
type Output = Result<Response<ResponseBody>, Error>;
9697

9798
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
98-
self.inner.as_mut().poll(cx)
99+
self.inner.get_mut().as_mut().poll(cx)
99100
}
100101
}

tests/http3.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use http::header::CONTENT_LENGTH;
77
use std::error::Error;
88
use support::server;
99

10+
fn assert_send_sync<T: Send + Sync>(_: &T) {}
11+
1012
#[tokio::test]
1113
async fn http3_request_full() {
1214
use http_body_util::BodyExt;
@@ -19,17 +21,18 @@ async fn http3_request_full() {
1921
});
2022

2123
let url = format!("https://{}/content-length", server.addr());
22-
let res = reqwest::Client::builder()
24+
let res_fut = reqwest::Client::builder()
2325
.http3_prior_knowledge()
2426
.danger_accept_invalid_certs(true)
2527
.build()
2628
.expect("client builder")
2729
.post(url)
2830
.version(http::Version::HTTP_3)
2931
.body("hello")
30-
.send()
31-
.await
32-
.expect("request");
32+
.send();
33+
34+
assert_send_sync(&res_fut);
35+
let res = res_fut.await.expect("request");
3336

3437
assert_eq!(res.version(), http::Version::HTTP_3);
3538
assert_eq!(res.status(), reqwest::StatusCode::OK);

0 commit comments

Comments
 (0)