fix(server): log and ignore connection errors on newly accepted sockets
This commit is contained in:
@@ -121,13 +121,14 @@ impl Stream for AddrIncoming {
|
|||||||
},
|
},
|
||||||
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
Ok(Async::NotReady) => return Ok(Async::NotReady),
|
||||||
Err(e) => {
|
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 {
|
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.
|
// Sleep 1s.
|
||||||
let delay = Instant::now() + Duration::from_secs(1);
|
let delay = Instant::now() + Duration::from_secs(1);
|
||||||
let mut timeout = Delay::new(delay);
|
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
|
/// The timeout is useful to handle resource exhaustion errors like ENFILE
|
||||||
/// and EMFILE. Otherwise, could enter into tight loop.
|
/// and EMFILE. Otherwise, could enter into tight loop.
|
||||||
fn is_connection_error(e: &io::Error) -> bool {
|
fn is_connection_error(e: &io::Error) -> bool {
|
||||||
e.kind() == io::ErrorKind::ConnectionRefused ||
|
match e.kind() {
|
||||||
e.kind() == io::ErrorKind::ConnectionAborted ||
|
io::ErrorKind::ConnectionRefused |
|
||||||
e.kind() == io::ErrorKind::ConnectionReset
|
io::ErrorKind::ConnectionAborted |
|
||||||
|
io::ErrorKind::ConnectionReset => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for AddrIncoming {
|
impl fmt::Debug for AddrIncoming {
|
||||||
|
|||||||
Reference in New Issue
Block a user