Skip to content

Commit bde399b

Browse files
authored
Merge pull request #771 from hatoo/fix-dns-http23
fix dns lookup on http2/http3
2 parents 93e6282 + a1246fd commit bde399b

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

src/client.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -994,11 +994,13 @@ fn is_hyper_error(res: &Result<RequestResult, ClientError>) -> bool {
994994
.unwrap_or(false)
995995
}
996996

997-
async fn setup_http2(client: &Client) -> Result<(ConnectionTime, SendRequestHttp2), ClientError> {
997+
async fn setup_http2<R: Rng>(
998+
client: &Client,
999+
rng: &mut R,
1000+
) -> Result<(ConnectionTime, SendRequestHttp2), ClientError> {
9981001
// Whatever rng state, all urls should have the same authority
999-
let mut rng: Pcg64Si = SeedableRng::from_seed([0, 0, 0, 0, 0, 0, 0, 0]);
1000-
let url = client.url_generator.generate(&mut rng)?;
1001-
let (connection_time, send_request) = client.connect_http2(&url, &mut rng).await?;
1002+
let url = client.url_generator.generate(rng)?;
1003+
let (connection_time, send_request) = client.connect_http2(&url, rng).await?;
10021004

10031005
Ok((connection_time, send_request))
10041006
}
@@ -1106,8 +1108,9 @@ pub async fn work(
11061108
let counter = counter.clone();
11071109
let client = client.clone();
11081110
tokio::spawn(async move {
1111+
let mut rng: Pcg64Si = SeedableRng::from_os_rng();
11091112
loop {
1110-
match setup_http2(&client).await {
1113+
match setup_http2(&client, &mut rng).await {
11111114
Ok((connection_time, send_request)) => {
11121115
let futures = (0..n_http2_parallel)
11131116
.map(|_| {
@@ -1276,8 +1279,9 @@ pub async fn work_with_qps(
12761279
let rx = rx.clone();
12771280
let client = client.clone();
12781281
tokio::spawn(async move {
1282+
let mut rng: Pcg64Si = SeedableRng::from_os_rng();
12791283
loop {
1280-
match setup_http2(&client).await {
1284+
match setup_http2(&client, &mut rng).await {
12811285
Ok((connection_time, send_request)) => {
12821286
let futures = (0..n_http_parallel)
12831287
.map(|_| {
@@ -1449,8 +1453,9 @@ pub async fn work_with_qps_latency_correction(
14491453
let rx = rx.clone();
14501454
let client = client.clone();
14511455
tokio::spawn(async move {
1456+
let mut rng: Pcg64Si = SeedableRng::from_os_rng();
14521457
loop {
1453-
match setup_http2(&client).await {
1458+
match setup_http2(&client, &mut rng).await {
14541459
Ok((connection_time, send_request)) => {
14551460
let futures = (0..n_http2_parallel)
14561461
.map(|_| {
@@ -1586,8 +1591,9 @@ pub async fn work_until(
15861591
tokio::spawn(async move {
15871592
let s = s.clone();
15881593
// Keep trying to establish or re-establish connections up to the deadline
1594+
let mut rng: Pcg64Si = SeedableRng::from_os_rng();
15891595
loop {
1590-
match setup_http2(&client).await {
1596+
match setup_http2(&client, &mut rng).await {
15911597
Ok((connection_time, send_request)) => {
15921598
// Setup the parallel workers for each HTTP2 connection
15931599
let futures = (0..n_http_parallel)
@@ -1790,8 +1796,9 @@ pub async fn work_until_with_qps(
17901796
let rx = rx.clone();
17911797
let s = s.clone();
17921798
tokio::spawn(async move {
1799+
let mut rng: Pcg64Si = SeedableRng::from_os_rng();
17931800
loop {
1794-
match setup_http2(&client).await {
1801+
match setup_http2(&client, &mut rng).await {
17951802
Ok((connection_time, send_request)) => {
17961803
let futures = (0..n_http2_parallel)
17971804
.map(|_| {
@@ -1998,8 +2005,9 @@ pub async fn work_until_with_qps_latency_correction(
19982005
let rx = rx.clone();
19992006
let s = s.clone();
20002007
tokio::spawn(async move {
2008+
let mut rng: Pcg64Si = SeedableRng::from_os_rng();
20012009
loop {
2002-
match setup_http2(&client).await {
2010+
match setup_http2(&client, &mut rng).await {
20032011
Ok((connection_time, send_request)) => {
20042012
let futures = (0..n_http2_parallel)
20052013
.map(|_| {
@@ -2141,6 +2149,7 @@ pub mod fast {
21412149
ClientError, ClientStateHttp1, ClientStateHttp2, HttpWorkType, is_cancel_error,
21422150
is_hyper_error, set_connection_time, setup_http2,
21432151
},
2152+
pcg64si::Pcg64Si,
21442153
result_data::ResultData,
21452154
};
21462155

@@ -2210,9 +2219,10 @@ pub mod fast {
22102219
local.spawn_local(Box::pin(async move {
22112220
let mut has_err = false;
22122221
let mut result_data_err = ResultData::default();
2222+
let mut rng: Pcg64Si = SeedableRng::from_os_rng();
22132223
loop {
22142224
let client = client.clone();
2215-
match setup_http2(&client).await {
2225+
match setup_http2(&client, &mut rng).await {
22162226
Ok((connection_time, send_request)) => {
22172227
let futures = (0..n_http_parallel)
22182228
.map(|_| {
@@ -2434,9 +2444,10 @@ pub mod fast {
24342444
local.spawn_local(Box::pin(async move {
24352445
let mut has_err = false;
24362446
let mut result_data_err = ResultData::default();
2447+
let mut rng: Pcg64Si = SeedableRng::from_os_rng();
24372448
loop {
24382449
let client = client.clone();
2439-
match setup_http2(&client).await {
2450+
match setup_http2(&client, &mut rng).await {
24402451
Ok((connection_time, send_request)) => {
24412452
let futures = (0..n_http_parallel)
24422453
.map(|_| {

src/client_h3.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,10 @@ async fn create_and_load_up_single_connection_http3(
280280
client: Arc<Client>,
281281
s: Arc<Semaphore>,
282282
) {
283+
let mut rng: Pcg64Si = SeedableRng::from_os_rng();
283284
loop {
284285
// create a HTTP3 connection
285-
match setup_http3(&client).await {
286+
match setup_http3(&client, &mut rng).await {
286287
Ok((connection_time, (h3_connection, send_request))) => {
287288
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel();
288289
let http3_driver = spawn_http3_driver(h3_connection, shutdown_rx).await;
@@ -363,13 +364,13 @@ async fn create_and_load_up_single_connection_http3(
363364
* This is structured to work very similarly to the `setup_http2`
364365
* function in `client.rs`
365366
*/
366-
pub(crate) async fn setup_http3(
367+
pub(crate) async fn setup_http3<R: Rng>(
367368
client: &Client,
369+
rng: &mut R,
368370
) -> Result<(ConnectionTime, SendRequestHttp3), ClientError> {
369371
// Whatever rng state, all urls should have the same authority
370-
let mut rng: Pcg64Si = SeedableRng::from_seed([0, 0, 0, 0, 0, 0, 0, 0]);
371-
let url = client.url_generator.generate(&mut rng)?;
372-
let (connection_time, send_request) = client.connect_http3(&url, &mut rng).await?;
372+
let url = client.url_generator.generate(rng)?;
373+
let (connection_time, send_request) = client.connect_http3(&url, rng).await?;
373374

374375
Ok((connection_time, send_request))
375376
}
@@ -457,9 +458,10 @@ pub(crate) fn http3_connection_fast_work_until(
457458
local.spawn_local(Box::pin(async move {
458459
let mut has_err = false;
459460
let mut result_data_err = ResultData::default();
461+
let mut rng: Pcg64Si = SeedableRng::from_os_rng();
460462
loop {
461463
let client = client.clone();
462-
match setup_http3(&client).await {
464+
match setup_http3(&client, &mut rng).await {
463465
Ok((connection_time, (h3_connection, send_request))) => {
464466
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel();
465467
let http3_driver = spawn_http3_driver(h3_connection, shutdown_rx).await;

0 commit comments

Comments
 (0)