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 <luciofranco14@gmail.com>
This commit is contained in:
Dom
2019-10-08 02:36:37 +01:00
committed by Lucio Franco
parent 01e72d9a95
commit 412a0bd697
+9 -1
View File
@@ -28,6 +28,8 @@ use tower::{
ServiceBuilder,
};
use tower_make::MakeService;
#[cfg(feature = "tls")]
use tracing::error;
type BoxService = tower::util::BoxService<Request<Body>, Response<BoxBody>, crate::Error>;
type Interceptor = Arc<dyn Layer<BoxService, Service = BoxService> + 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;
}