From c33861a13b02e63849670d308a1283213c2887f0 Mon Sep 17 00:00:00 2001 From: Adrian Catangiu Date: Mon, 30 Mar 2020 20:54:00 +0300 Subject: [PATCH] Handle ErrorKind::Interrupted when waiting for events ErrorKind::Interrupted (libc::EINTR) errors should not break the HttpServer requests loop, they are internally consumed and reported as no events rather than requests errors. Signed-off-by: Adrian Catangiu --- coverage_config.json | 2 +- src/server.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/coverage_config.json b/coverage_config.json index 258501e..ecf738b 100644 --- a/coverage_config.json +++ b/coverage_config.json @@ -1 +1 @@ -{"coverage_score": 92.8, "exclude_path": "", "crate_features": ""} +{"coverage_score": 92.4, "exclude_path": "", "crate_features": ""} diff --git a/src/server.rs b/src/server.rs index e915b97..cfaa832 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,5 +1,6 @@ // Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 + extern crate epoll; use std::collections::HashMap; @@ -301,8 +302,11 @@ impl HttpServer { // current thread until at least one event is received. // The received notifications will then populate the `events` array with // `event_count` elements, where 1 <= event_count <= MAX_CONNECTIONS. - let event_count = - epoll::wait(self.epoll_fd, -1, &mut events[..]).map_err(ServerError::IOError)?; + let event_count = match epoll::wait(self.epoll_fd, -1, &mut events[..]) { + Ok(event_count) => event_count, + Err(e) if e.kind() == std::io::ErrorKind::Interrupted => 0, + Err(e) => return Err(ServerError::IOError(e)), + }; // We use `take()` on the iterator over `events` as, even though only // `events_count` events have been inserted into `events`, the size of // the array is still `MAX_CONNECTIONS`, so we discard empty elements