Skip to content

Commit 412a0bd

Browse files
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>
1 parent 01e72d9 commit 412a0bd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

tonic/src/transport/server.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ use tower::{
2828
ServiceBuilder,
2929
};
3030
use tower_make::MakeService;
31+
#[cfg(feature = "tls")]
32+
use tracing::error;
3133

3234
type BoxService = tower::util::BoxService<Request<Body>, Response<BoxBody>, crate::Error>;
3335
type Interceptor = Arc<dyn Layer<BoxService, Service = BoxService> + Send + Sync + 'static>;
@@ -207,7 +209,13 @@ impl Server {
207209
#[cfg(feature = "tls")]
208210
{
209211
if let Some(tls) = &self.tls {
210-
let io = tls.connect(stream.into_inner()).await?;
212+
let io = match tls.connect(stream.into_inner()).await {
213+
Ok(io) => io,
214+
Err(error) => {
215+
error!(message = "Unable to accept incoming connection.", %error);
216+
continue
217+
},
218+
};
211219
yield BoxedIo::new(io);
212220
continue;
213221
}

0 commit comments

Comments
 (0)