fix(transport): Propagate errors in tls_config instead of unwrap/panic (#385)

* Propagate errors in tls_config instead of unwrap

Ran into `tls_connector` failing and causing our app to panic and shutdown as it seems there wasn't any way to avoid panicking in `tls_config`.

So after talking to @LucioFranco briefly `tls_config` now returns a `Result` instead and propagates errors to the caller, where they can be handled.

* Fix compile warning when tls feature is disabled
This commit is contained in:
Johan Andersson
2020-07-06 09:18:10 -04:00
committed by GitHub
parent f085aba302
commit 3b9d6a6262
10 changed files with 28 additions and 17 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.domain_name("pubsub.googleapis.com");
let channel = Channel::from_static(ENDPOINT)
.tls_config(tls_config)
.tls_config(tls_config)?
.connect()
.await?;
+1 -1
View File
@@ -15,7 +15,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.domain_name("example.com");
let channel = Channel::from_static("http://[::1]:50051")
.tls_config(tls)
.tls_config(tls)?
.connect()
.await?;
+1 -1
View File
@@ -60,7 +60,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let server = EchoServer::default();
Server::builder()
.tls_config(ServerTlsConfig::new().identity(identity))
.tls_config(ServerTlsConfig::new().identity(identity))?
.add_service(pb::echo_server::EchoServer::new(server))
.serve(addr)
.await?;
+1 -1
View File
@@ -19,7 +19,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.identity(client_identity);
let channel = Channel::from_static("http://[::1]:50051")
.tls_config(tls)
.tls_config(tls)?
.connect()
.await?;
+1 -1
View File
@@ -68,7 +68,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.client_ca_root(client_ca_cert);
Server::builder()
.tls_config(tls)
.tls_config(tls)?
.add_service(pb::echo_server::EchoServer::new(server))
.serve(addr)
.await?;