Skip to content

Commit 4859a73

Browse files
authored
Add connection timeout to connect_with_connector_lazy (#1619)
Currently connect_with_connector_lazy doesn't respect connection timeouts. This means that if you have a misbehaving server a request that's connecting lazily can hang for the client without timing out. This commit adds the timeout to the custom connector if it has been set on the endpoint, bringing the behaviour in line with other connect methods.
1 parent 227b169 commit 4859a73

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tonic/src/transport/channel/endpoint.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,13 @@ impl Endpoint {
390390
crate::Error: From<C::Error> + Send + 'static,
391391
{
392392
let connector = self.connector(connector);
393-
Channel::new(connector, self.clone())
393+
if let Some(connect_timeout) = self.connect_timeout {
394+
let mut connector = hyper_timeout::TimeoutConnector::new(connector);
395+
connector.set_connect_timeout(Some(connect_timeout));
396+
Channel::new(connector, self.clone())
397+
} else {
398+
Channel::new(connector, self.clone())
399+
}
394400
}
395401

396402
/// Get the endpoint uri.

0 commit comments

Comments
 (0)