Skip to content

Commit 7388013

Browse files
committed
Use connect deadline instead of timeout
1 parent ae686c8 commit 7388013

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

grpc/src/client/transport/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{rt::Runtime, service::Service};
2+
use std::time::Instant;
23
use std::{sync::Arc, time::Duration};
34

45
mod registry;
@@ -34,7 +35,7 @@ pub(crate) struct TransportOptions {
3435
pub rate_limit: Option<(u64, Duration)>,
3536
pub tcp_keepalive: Option<Duration>,
3637
pub tcp_nodelay: bool,
37-
pub connect_timeout: Option<Duration>,
38+
pub connect_deadline: Option<Instant>,
3839
}
3940

4041
#[async_trait]

grpc/src/client/transport/tonic/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use http::Uri;
1717
use hyper::client::conn::http2::Builder;
1818
use hyper::client::conn::http2::SendRequest;
1919
use std::any::Any;
20+
use std::time::Instant;
2021
use std::{
2122
error::Error,
2223
future::Future,
@@ -191,7 +192,8 @@ impl Transport for TransportBuilder {
191192
keepalive: opts.tcp_keepalive,
192193
},
193194
);
194-
let tcp_stream = if let Some(timeout) = opts.connect_timeout {
195+
let tcp_stream = if let Some(deadline) = opts.connect_deadline {
196+
let timeout = deadline.saturating_duration_since(Instant::now());
195197
tokio::select! {
196198
_ = runtime.sleep(timeout) => {
197199
return Err("timed out waiting for TCP stream to connect".to_string())

0 commit comments

Comments
 (0)