Skip to content

Commit

Permalink
fix(server): log and ignore connection errors on newly accepted sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Oct 9, 2018
1 parent 37ec724 commit 66a857d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/server/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@ impl Stream for AddrIncoming {
},
Ok(Async::NotReady) => return Ok(Async::NotReady),
Err(e) => {
// 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 {
// Connection errors can be ignored directly, continue by
// accepting the next request.
if is_connection_error(&e) {
debug!("accepted connection already errored: {}", e);
continue;
}
// Sleep 1s.
let delay = Instant::now() + Duration::from_secs(1);
let mut timeout = Delay::new(delay);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 66a857d

Please sign in to comment.