From 510e13049088fc963956bd39f751fc8f769777b1 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 3 Dec 2016 14:35:22 +1100 Subject: [PATCH] Handle epoll hangups in userproxy_recv even if epollin is set, but after reading any data available, and do not skip processing if proxy is not marked alive yet. --- src/generator.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/generator.c b/src/generator.c index 42b0177e..4271dd08 100644 --- a/src/generator.c +++ b/src/generator.c @@ -2187,13 +2187,6 @@ static void *userproxy_recv(void *arg) if (unlikely(!proxy->authorised)) continue; - if ((event.events & (EPOLLHUP | EPOLLERR | EPOLLRDHUP)) && - !(event.events & EPOLLIN)) { - LOGNOTICE("Proxy %d:%d %s hung up in epoll_wait", proxy->id, - proxy->subid, proxy->url); - disable_subproxy(gdata, proxy->parent, proxy); - continue; - } now = time(NULL); mutex_lock(&gdata->notify_lock); @@ -2219,23 +2212,35 @@ static void *userproxy_recv(void *arg) timeout = 0; cs = &proxy->cs; +#if 0 + /* Is this needed at all? */ if (!proxy->alive) continue; +#endif - cksem_wait(&cs->sem); - while ((ret = read_socket_line(cs, &timeout)) > 0) { - /* proxy may have been recycled here if it is not a - * parent and reconnect was issued */ - if (parse_method(ckp, proxy, cs->buf)) - continue; - /* If it's not a method it should be a share result */ - if (!parse_share(gdata, proxy, cs->buf)) { - LOGNOTICE("Proxy %d:%d unhandled stratum message: %s", - proxy->id, proxy->subid, cs->buf); + if (likely(event.events & EPOLLIN)) { + cksem_wait(&cs->sem); + while ((ret = read_socket_line(cs, &timeout)) > 0) { + timeout = 0; + /* proxy may have been recycled here if it is not a + * parent and reconnect was issued */ + if (parse_method(ckp, proxy, cs->buf)) + continue; + /* If it's not a method it should be a share result */ + if (!parse_share(gdata, proxy, cs->buf)) { + LOGNOTICE("Proxy %d:%d unhandled stratum message: %s", + proxy->id, proxy->subid, cs->buf); + } } - timeout = 0; + cksem_post(&cs->sem); + } + + if ((event.events & (EPOLLHUP | EPOLLERR | EPOLLRDHUP))) { + LOGNOTICE("Proxy %d:%d %s hung up in epoll_wait", proxy->id, + proxy->subid, proxy->url); + disable_subproxy(gdata, proxy->parent, proxy); + continue; } - cksem_post(&cs->sem); } return NULL; }