Browse Source

Make userproxy_recv take same precautions with hangups while reading as proxy_recv.

master
Con Kolivas 8 years ago
parent
commit
6700c0fae0
  1. 29
      src/generator.c

29
src/generator.c

@ -2363,6 +2363,7 @@ static void *userproxy_recv(void *arg)
while (42) { while (42) {
proxy_instance_t *proxy, *tmpproxy; proxy_instance_t *proxy, *tmpproxy;
bool message = false, hup = false;
share_msg_t *share, *tmpshare; share_msg_t *share, *tmpshare;
notify_instance_t *ni, *tmp; notify_instance_t *ni, *tmp;
connsock_t *cs; connsock_t *cs;
@ -2414,7 +2415,6 @@ static void *userproxy_recv(void *arg)
} }
mutex_unlock(&gdata->share_lock); mutex_unlock(&gdata->share_lock);
timeout = 0;
cs = &proxy->cs; cs = &proxy->cs;
#if 0 #if 0
@ -2423,9 +2423,30 @@ static void *userproxy_recv(void *arg)
continue; continue;
#endif #endif
if ((event.events & (EPOLLHUP | EPOLLERR | EPOLLRDHUP))) {
LOGNOTICE("Proxy %d:%d %s hangup in userproxy_recv", proxy->id,
proxy->subid, proxy->url);
hup = true;
}
if (likely(event.events & EPOLLIN)) { if (likely(event.events & EPOLLIN)) {
timeout = 30;
cksem_wait(&cs->sem); cksem_wait(&cs->sem);
while ((ret = read_socket_line(cs, &timeout)) > 0) { ret = read_socket_line(cs, &timeout);
/* If we are unable to read anything within 30
* seconds at this point after EPOLLIN is set
* then the socket is dead. */
if (ret < 1) {
LOGNOTICE("Proxy %d:%d %s failed to read_socket_line in userproxy_recv",
proxy->id, proxy->subid, proxy->url);
hup = true;
} else {
message = true;
timeout = 0;
}
while (message || (ret = read_socket_line(cs, &timeout)) > 0) {
message = false;
timeout = 0; timeout = 0;
/* proxy may have been recycled here if it is not a /* proxy may have been recycled here if it is not a
* parent and reconnect was issued */ * parent and reconnect was issued */
@ -2440,9 +2461,7 @@ static void *userproxy_recv(void *arg)
cksem_post(&cs->sem); cksem_post(&cs->sem);
} }
if ((event.events & (EPOLLHUP | EPOLLERR | EPOLLRDHUP))) { if (hup) {
LOGNOTICE("Proxy %d:%d %s hung up in epoll_wait", proxy->id,
proxy->subid, proxy->url);
disable_subproxy(gdata, proxy->parent, proxy); disable_subproxy(gdata, proxy->parent, proxy);
continue; continue;
} }

Loading…
Cancel
Save