From 412a0bd697b4822b94c55cb18d2373a6ed75b690 Mon Sep 17 00:00:00 2001 From: Dom Date: Tue, 8 Oct 2019 02:36:37 +0100 Subject: [PATCH] fix(transport): Avoid exit after bad TLS handshake (#51) * transport: no crash after bad TLS handshake Prevents the server exiting after a bad TLS handshake / error during accept(). Instead the connection is dropped and the server continues to serve new clients. Previously an error would bubble up from the TLS library (tested with rustls) and cause hyper to exit with: [src/main.rs:85] &e = Error( Server, Error( Accept, Custom { kind: InvalidData, error: CorruptMessage, }, ), ) * transport: add tracing error for TLS handshake failure Co-Authored-By: Lucio Franco --- tonic/src/transport/server.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tonic/src/transport/server.rs b/tonic/src/transport/server.rs index 34cd327..9878a2b 100644 --- a/tonic/src/transport/server.rs +++ b/tonic/src/transport/server.rs @@ -28,6 +28,8 @@ use tower::{ ServiceBuilder, }; use tower_make::MakeService; +#[cfg(feature = "tls")] +use tracing::error; type BoxService = tower::util::BoxService, Response, crate::Error>; type Interceptor = Arc + Send + Sync + 'static>; @@ -207,7 +209,13 @@ impl Server { #[cfg(feature = "tls")] { if let Some(tls) = &self.tls { - let io = tls.connect(stream.into_inner()).await?; + let io = match tls.connect(stream.into_inner()).await { + Ok(io) => io, + Err(error) => { + error!(message = "Unable to accept incoming connection.", %error); + continue + }, + }; yield BoxedIo::new(io); continue; }