Skip to content

Commit

Permalink
fix(transport): Avoid exit after bad TLS handshake (#51)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
domodwyer and LucioFranco committed Oct 8, 2019
1 parent 01e72d9 commit 412a0bd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tonic/src/transport/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 412a0bd

Please sign in to comment.