diff --git a/tonic/src/transport/server/incoming.rs b/tonic/src/transport/server/incoming.rs index 3672f8ee5..e55c6a171 100644 --- a/tonic/src/transport/server/incoming.rs +++ b/tonic/src/transport/server/incoming.rs @@ -33,7 +33,7 @@ where while let Some(item) = incoming.next().await { yield match item { Ok(_) => item.map(ServerIo::new_io)?, - Err(e) => match handle_accept_error(e) { + Err(e) => match handle_tcp_accept_error(e) { ControlFlow::Continue(()) => continue, ControlFlow::Break(e) => Err(e)?, } @@ -74,11 +74,16 @@ where yield io; } - SelectOutput::Err(e) => match handle_accept_error(e) { + SelectOutput::TcpErr(e) => match handle_tcp_accept_error(e) { ControlFlow::Continue(()) => continue, ControlFlow::Break(e) => Err(e)?, } + SelectOutput::TlsErr(e) => { + tracing::debug!(error = %e, "tls accept error"); + continue; + } + SelectOutput::Done => { break; } @@ -87,7 +92,7 @@ where } } -fn handle_accept_error(e: impl Into) -> ControlFlow { +fn handle_tcp_accept_error(e: impl Into) -> ControlFlow { let e = e.into(); tracing::debug!(error = %e, "accept loop error"); if let Some(e) = e.downcast_ref::() { @@ -97,8 +102,6 @@ fn handle_accept_error(e: impl Into) -> ControlFlow | io::ErrorKind::ConnectionReset | io::ErrorKind::BrokenPipe | io::ErrorKind::Interrupted - | io::ErrorKind::InvalidData // Raised if TLS handshake failed - | io::ErrorKind::UnexpectedEof // Raised if TLS handshake failed | io::ErrorKind::WouldBlock | io::ErrorKind::TimedOut ) { @@ -121,7 +124,7 @@ where return match incoming.try_next().await { Ok(Some(stream)) => SelectOutput::Incoming(stream), Ok(None) => SelectOutput::Done, - Err(e) => SelectOutput::Err(e.into()), + Err(e) => SelectOutput::TcpErr(e.into()), }; } @@ -130,15 +133,15 @@ where match stream { Ok(Some(stream)) => SelectOutput::Incoming(stream), Ok(None) => SelectOutput::Done, - Err(e) => SelectOutput::Err(e.into()), + Err(e) => SelectOutput::TcpErr(e.into()), } } accept = tasks.join_next() => { match accept.expect("JoinSet should never end") { Ok(Ok(io)) => SelectOutput::Io(io), - Ok(Err(e)) => SelectOutput::Err(e), - Err(e) => SelectOutput::Err(e.into()), + Ok(Err(e)) => SelectOutput::TlsErr(e), + Err(e) => SelectOutput::TlsErr(e.into()), } } } @@ -148,7 +151,8 @@ where enum SelectOutput { Incoming(A), Io(ServerIo), - Err(crate::Error), + TcpErr(crate::Error), + TlsErr(crate::Error), Done, }