Skip to content

Commit 66a857d

Browse files
committed
fix(server): log and ignore connection errors on newly accepted sockets
1 parent 37ec724 commit 66a857d

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/server/tcp.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,14 @@ impl Stream for AddrIncoming {
121121
},
122122
Ok(Async::NotReady) => return Ok(Async::NotReady),
123123
Err(e) => {
124+
// Connection errors can be ignored directly, continue by
125+
// accepting the next request.
126+
if is_connection_error(&e) {
127+
debug!("accepted connection already errored: {}", e);
128+
continue;
129+
}
130+
124131
if self.sleep_on_errors {
125-
// Connection errors can be ignored directly, continue by
126-
// accepting the next request.
127-
if is_connection_error(&e) {
128-
debug!("accepted connection already errored: {}", e);
129-
continue;
130-
}
131132
// Sleep 1s.
132133
let delay = Instant::now() + Duration::from_secs(1);
133134
let mut timeout = Delay::new(delay);
@@ -165,9 +166,12 @@ impl Stream for AddrIncoming {
165166
/// The timeout is useful to handle resource exhaustion errors like ENFILE
166167
/// and EMFILE. Otherwise, could enter into tight loop.
167168
fn is_connection_error(e: &io::Error) -> bool {
168-
e.kind() == io::ErrorKind::ConnectionRefused ||
169-
e.kind() == io::ErrorKind::ConnectionAborted ||
170-
e.kind() == io::ErrorKind::ConnectionReset
169+
match e.kind() {
170+
io::ErrorKind::ConnectionRefused |
171+
io::ErrorKind::ConnectionAborted |
172+
io::ErrorKind::ConnectionReset => true,
173+
_ => false,
174+
}
171175
}
172176

173177
impl fmt::Debug for AddrIncoming {

0 commit comments

Comments
 (0)