Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: swallow TLS errors in the accept loop #1990

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions tonic/src/transport/server/incoming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -87,7 +92,7 @@ where
}
}

fn handle_accept_error(e: impl Into<crate::Error>) -> ControlFlow<crate::Error> {
fn handle_tcp_accept_error(e: impl Into<crate::Error>) -> ControlFlow<crate::Error> {
djc marked this conversation as resolved.
Show resolved Hide resolved
let e = e.into();
tracing::debug!(error = %e, "accept loop error");
if let Some(e) = e.downcast_ref::<io::Error>() {
Expand All @@ -97,8 +102,6 @@ fn handle_accept_error(e: impl Into<crate::Error>) -> ControlFlow<crate::Error>
| 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
) {
Expand All @@ -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()),
};
}

Expand All @@ -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()),
}
}
}
Expand All @@ -148,7 +151,8 @@ where
enum SelectOutput<A> {
Incoming(A),
Io(ServerIo<A>),
Err(crate::Error),
TcpErr(crate::Error),
TlsErr(crate::Error),
Done,
}

Expand Down