From dcc5ec2c848f57c600ef127f1ed3640154a67cbe Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 6 Mar 2019 10:36:11 -0500 Subject: [PATCH] Add a safety timeout to epoll Add a safety timeout just in case something goes wrong with the use of timerfd. This way the process should't be stuck forever. Signed-off-by: Simo Sorce [rharwood@redhat.com: remove outdated comment] Reviewed-by: Robbie Harwood Merges: #241 (cherry picked from commit d55be9fa2455fe52b6eb904ad427f22141ab3f26) (cherry picked from commit a494f23b6d8d43fe1a824cd69c3dd93a18fc75a1) --- proxy/src/client/gpm_common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/proxy/src/client/gpm_common.c b/proxy/src/client/gpm_common.c index 554c91c..462d88b 100644 --- a/proxy/src/client/gpm_common.c +++ b/proxy/src/client/gpm_common.c @@ -14,6 +14,7 @@ #define FRAGMENT_BIT (1 << 31) #define RESPONSE_TIMEOUT 15 +#define SAFETY_TIMEOUT RESPONSE_TIMEOUT * 10 * 1000 #define MAX_TIMEOUT_RETRY 3 struct gpm_ctx { @@ -287,7 +288,7 @@ static int gpm_epoll_wait(struct gpm_ctx *gpmctx, uint32_t event_flags) } do { - epoll_ret = epoll_wait(gpmctx->epollfd, events, 2, -1); + epoll_ret = epoll_wait(gpmctx->epollfd, events, 2, SAFETY_TIMEOUT); } while (epoll_ret < 0 && errno == EINTR); if (epoll_ret < 0) { @@ -295,8 +296,6 @@ static int gpm_epoll_wait(struct gpm_ctx *gpmctx, uint32_t event_flags) ret = errno; gpm_epoll_close(gpmctx); } else if (epoll_ret == 0) { - /* Shouldn't happen as timeout == -1; treat it like a timeout - * occurred. */ ret = ETIMEDOUT; gpm_epoll_close(gpmctx); } else if (epoll_ret == 1 && events[0].data.fd == gpmctx->timerfd) {