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

Prevent server from exiting on ECONNABORTED #1874

Merged
merged 5 commits into from
Aug 20, 2024
Merged
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
18 changes: 16 additions & 2 deletions tonic/src/transport/server/incoming.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::service::ServerIo;
#[cfg(feature = "tls")]
use super::service::TlsAcceptor;
#[cfg(not(feature = "tls"))]
use std::io;
use std::{
net::{SocketAddr, TcpListener as StdTcpListener},
pin::{pin, Pin},
Expand All @@ -27,7 +29,19 @@ where
let mut incoming = pin!(incoming);

while let Some(item) = incoming.next().await {
yield item.map(ServerIo::new_io)?
yield match item {
Ok(_) => item.map(ServerIo::new_io)?,
Err(e) => {
let e = e.into();
tracing::debug!(error = %e, "accept loop error");
if let Some(e) = e.downcast_ref::<io::Error>() {
if e.kind() == io::ErrorKind::ConnectionAborted {
continue;
}
}
Err(e)?
}
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok(_) => item.map(ServerIo::new_io)?

could also be written as

Ok(io) => Ok::<ServerIo<IO>, crate::Error>(ServerIo::new_io(io))?,

but in terms of readability and diff, I opted for the former (any better ideas?).

}
Expand Down Expand Up @@ -65,7 +79,7 @@ where
}

SelectOutput::Err(e) => {
tracing::debug!(message = "Accept loop error.", error = %e);
tracing::debug!(error = %e, "accept loop error");
}

SelectOutput::Done => {
Expand Down