Browse Source

Fix userproxies not having their semaphores initialised and avoid trying to process epoll responses from proxies not marked alive

master
Con Kolivas 9 years ago
parent
commit
b6ceb9b484
  1. 18
      src/generator.c

18
src/generator.c

@ -1776,13 +1776,18 @@ static bool proxy_alive(ckpool_t *ckp, proxy_instance_t *proxi, connsock_t *cs,
bool ret = false; bool ret = false;
/* Has this proxy already been reconnected? */ /* Has this proxy already been reconnected? */
if (cs->fd > 0) if (proxi->alive)
return true; return true;
if (proxi->disabled) if (proxi->disabled)
return false; return false;
/* Serialise all send/recvs here with the cs semaphore */ /* Serialise all send/recvs here with the cs semaphore */
cksem_wait(&cs->sem); cksem_wait(&cs->sem);
/* Check again after grabbing semaphore */
if (unlikely(proxi->alive)) {
ret = true;
goto out;
}
if (!extract_sockaddr(proxi->url, &cs->url, &cs->port)) { if (!extract_sockaddr(proxi->url, &cs->url, &cs->port)) {
LOGWARNING("Failed to extract address from %s", proxi->url); LOGWARNING("Failed to extract address from %s", proxi->url);
goto out; goto out;
@ -1822,8 +1827,6 @@ static bool proxy_alive(ckpool_t *ckp, proxy_instance_t *proxi, connsock_t *cs,
} }
proxi->authorised = ret = true; proxi->authorised = ret = true;
out: out:
cksem_post(&cs->sem);
if (!ret) { if (!ret) {
send_stratifier_deadproxy(ckp, proxi->id, proxi->subid); send_stratifier_deadproxy(ckp, proxi->id, proxi->subid);
/* Close and invalidate the file handle */ /* Close and invalidate the file handle */
@ -1831,6 +1834,8 @@ out:
Close(cs->fd); Close(cs->fd);
} }
proxi->alive = ret; proxi->alive = ret;
cksem_post(&cs->sem);
return ret; return ret;
} }
@ -2072,6 +2077,8 @@ static void *proxy_recv(void *arg)
if (likely(ret > 0)) { if (likely(ret > 0)) {
subproxy = event.data.ptr; subproxy = event.data.ptr;
cs = &subproxy->cs; cs = &subproxy->cs;
if (!subproxy->alive)
continue;
/* Serialise messages from here once we have a cs by /* Serialise messages from here once we have a cs by
* holding the semaphore. */ * holding the semaphore. */
@ -2185,6 +2192,9 @@ static void *userproxy_recv(void *arg)
timeout = 0; timeout = 0;
cs = &proxy->cs; cs = &proxy->cs;
if (!proxy->alive)
continue;
cksem_wait(&cs->sem); cksem_wait(&cs->sem);
while ((ret = read_socket_line(cs, &timeout)) > 0) { while ((ret = read_socket_line(cs, &timeout)) > 0) {
/* proxy may have been recycled here if it is not a /* proxy may have been recycled here if it is not a
@ -2332,6 +2342,8 @@ static proxy_instance_t *__add_userproxy(ckpool_t *ckp, gdata_t *gdata, const in
proxy->auth = auth; proxy->auth = auth;
proxy->pass = pass; proxy->pass = pass;
proxy->ckp = proxy->cs.ckp = ckp; proxy->ckp = proxy->cs.ckp = ckp;
cksem_init(&proxy->cs.sem);
cksem_post(&proxy->cs.sem);
HASH_ADD_INT(gdata->proxies, id, proxy); HASH_ADD_INT(gdata->proxies, id, proxy);
return proxy; return proxy;
} }

Loading…
Cancel
Save