fix(server): log and ignore connection errors on newly accepted sockets

This commit is contained in:
Sean McArthur
2018-10-09 16:04:31 -07:00
parent 37ec724fd6
commit 66a857d801

View File

@@ -121,13 +121,14 @@ impl Stream for AddrIncoming {
},
Ok(Async::NotReady) => return Ok(Async::NotReady),
Err(e) => {
if self.sleep_on_errors {
// Connection errors can be ignored directly, continue by
// accepting the next request.
if is_connection_error(&e) {
debug!("accepted connection already errored: {}", e);
continue;
}
if self.sleep_on_errors {
// Sleep 1s.
let delay = Instant::now() + Duration::from_secs(1);
let mut timeout = Delay::new(delay);
@@ -165,9 +166,12 @@ impl Stream for AddrIncoming {
/// The timeout is useful to handle resource exhaustion errors like ENFILE
/// and EMFILE. Otherwise, could enter into tight loop.
fn is_connection_error(e: &io::Error) -> bool {
e.kind() == io::ErrorKind::ConnectionRefused ||
e.kind() == io::ErrorKind::ConnectionAborted ||
e.kind() == io::ErrorKind::ConnectionReset
match e.kind() {
io::ErrorKind::ConnectionRefused |
io::ErrorKind::ConnectionAborted |
io::ErrorKind::ConnectionReset => true,
_ => false,
}
}
impl fmt::Debug for AddrIncoming {