Skip to content

Commit a00200e

Browse files
authored
server: swallow TLS errors in the accept loop (#1990)
* fix: swallow TLS errors in the accept loop * chore: address feedback
1 parent 71dcf86 commit a00200e

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

tonic/src/transport/server/incoming.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
while let Some(item) = incoming.next().await {
3434
yield match item {
3535
Ok(_) => item.map(ServerIo::new_io)?,
36-
Err(e) => match handle_accept_error(e) {
36+
Err(e) => match handle_tcp_accept_error(e) {
3737
ControlFlow::Continue(()) => continue,
3838
ControlFlow::Break(e) => Err(e)?,
3939
}
@@ -74,11 +74,16 @@ where
7474
yield io;
7575
}
7676

77-
SelectOutput::Err(e) => match handle_accept_error(e) {
77+
SelectOutput::TcpErr(e) => match handle_tcp_accept_error(e) {
7878
ControlFlow::Continue(()) => continue,
7979
ControlFlow::Break(e) => Err(e)?,
8080
}
8181

82+
SelectOutput::TlsErr(e) => {
83+
tracing::debug!(error = %e, "tls accept error");
84+
continue;
85+
}
86+
8287
SelectOutput::Done => {
8388
break;
8489
}
@@ -87,7 +92,7 @@ where
8792
}
8893
}
8994

90-
fn handle_accept_error(e: impl Into<crate::Error>) -> ControlFlow<crate::Error> {
95+
fn handle_tcp_accept_error(e: impl Into<crate::Error>) -> ControlFlow<crate::Error> {
9196
let e = e.into();
9297
tracing::debug!(error = %e, "accept loop error");
9398
if let Some(e) = e.downcast_ref::<io::Error>() {
@@ -97,8 +102,6 @@ fn handle_accept_error(e: impl Into<crate::Error>) -> ControlFlow<crate::Error>
97102
| io::ErrorKind::ConnectionReset
98103
| io::ErrorKind::BrokenPipe
99104
| io::ErrorKind::Interrupted
100-
| io::ErrorKind::InvalidData // Raised if TLS handshake failed
101-
| io::ErrorKind::UnexpectedEof // Raised if TLS handshake failed
102105
| io::ErrorKind::WouldBlock
103106
| io::ErrorKind::TimedOut
104107
) {
@@ -121,7 +124,7 @@ where
121124
return match incoming.try_next().await {
122125
Ok(Some(stream)) => SelectOutput::Incoming(stream),
123126
Ok(None) => SelectOutput::Done,
124-
Err(e) => SelectOutput::Err(e.into()),
127+
Err(e) => SelectOutput::TcpErr(e.into()),
125128
};
126129
}
127130

@@ -130,15 +133,15 @@ where
130133
match stream {
131134
Ok(Some(stream)) => SelectOutput::Incoming(stream),
132135
Ok(None) => SelectOutput::Done,
133-
Err(e) => SelectOutput::Err(e.into()),
136+
Err(e) => SelectOutput::TcpErr(e.into()),
134137
}
135138
}
136139

137140
accept = tasks.join_next() => {
138141
match accept.expect("JoinSet should never end") {
139142
Ok(Ok(io)) => SelectOutput::Io(io),
140-
Ok(Err(e)) => SelectOutput::Err(e),
141-
Err(e) => SelectOutput::Err(e.into()),
143+
Ok(Err(e)) => SelectOutput::TlsErr(e),
144+
Err(e) => SelectOutput::TlsErr(e.into()),
142145
}
143146
}
144147
}
@@ -148,7 +151,8 @@ where
148151
enum SelectOutput<A> {
149152
Incoming(A),
150153
Io(ServerIo<A>),
151-
Err(crate::Error),
154+
TcpErr(crate::Error),
155+
TlsErr(crate::Error),
152156
Done,
153157
}
154158

0 commit comments

Comments
 (0)