Skip to content

Commit

Permalink
Add connection timeout to connect_with_connector_lazy (#1619)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Benjscho committed Feb 1, 2024
1 parent 227b169 commit 4859a73
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,13 @@ impl Endpoint {
crate::Error: From<C::Error> + Send + 'static,
{
let connector = self.connector(connector);
Channel::new(connector, self.clone())
if let Some(connect_timeout) = self.connect_timeout {
let mut connector = hyper_timeout::TimeoutConnector::new(connector);
connector.set_connect_timeout(Some(connect_timeout));
Channel::new(connector, self.clone())
} else {
Channel::new(connector, self.clone())
}
}

/// Get the endpoint uri.
Expand Down

0 comments on commit 4859a73

Please sign in to comment.