Skip to content

Commit

Permalink
Remove connection timeout to prevent macos crash
Browse files Browse the repository at this point in the history
  • Loading branch information
hatoo committed Jan 25, 2024
1 parent aaaab95 commit 71168b8
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,41 +271,28 @@ impl Client {
addr: (std::net::IpAddr, u16),
url: &Url,
) -> Result<Stream, ClientError> {
// TODO: Allow the connect timeout to be configured
let timeout_duration = tokio::time::Duration::from_secs(5);

if url.scheme() == "https" {
// If we do not put a timeout here then the connections attempts will
// linger long past the configured timeout
let stream = tokio::time::timeout(timeout_duration, self.tls_client(addr, url)).await;
let stream = self.tls_client(addr, url).await;
return match stream {
Ok(Ok(stream)) => Ok(stream),
Ok(Err(err)) => Err(err),
Err(_) => Err(ClientError::Timeout),
Ok(stream) => Ok(stream),
Err(err) => Err(err),
};
}
#[cfg(unix)]
if let Some(socket_path) = &self.unix_socket {
let stream = tokio::time::timeout(
timeout_duration,
tokio::net::UnixStream::connect(socket_path),
)
.await;
let stream = tokio::net::UnixStream::connect(socket_path).await;
return match stream {
Ok(Ok(stream)) => Ok(Stream::Unix(stream)),
Ok(Err(err)) => Err(ClientError::IoError(err)),
Err(_) => Err(ClientError::Timeout),
Ok(stream) => Ok(Stream::Unix(stream)),
Err(err) => Err(ClientError::IoError(err)),
};
}
let stream =
tokio::time::timeout(timeout_duration, tokio::net::TcpStream::connect(addr)).await;
let stream = tokio::net::TcpStream::connect(addr).await;
match stream {
Ok(Ok(stream)) => {
Ok(stream) => {
stream.set_nodelay(true)?;
Ok(Stream::Tcp(stream))
}
Ok(Err(err)) => Err(ClientError::IoError(err)),
Err(_) => Err(ClientError::Timeout),
Err(err) => Err(ClientError::IoError(err)),
}
}

Expand Down

0 comments on commit 71168b8

Please sign in to comment.