Browse Source

Disable proxies in the generator in the receiving threads only to avoid races.

master
Con Kolivas 7 years ago
parent
commit
7f3cbc587b
  1. 21
      src/generator.c

21
src/generator.c

@ -1166,7 +1166,9 @@ static void close_proxy_socket(proxy_instance_t *proxy, proxy_instance_t *subpro
/* Remove the subproxy from the proxi list and put it on the dead list. /* Remove the subproxy from the proxi list and put it on the dead list.
* Further use of the subproxy pointer may point to a new proxy but will not * Further use of the subproxy pointer may point to a new proxy but will not
* dereference. This will only disable subproxies so parent proxies need to * dereference. This will only disable subproxies so parent proxies need to
* have their disabled bool set manually. */ * have their disabled bool set manually. This should only be called from the
* receiving threads *proxy_recv to avoid a race on the proxy or connsock data.
*/
static void disable_subproxy(gdata_t *gdata, proxy_instance_t *proxi, proxy_instance_t *subproxy) static void disable_subproxy(gdata_t *gdata, proxy_instance_t *proxi, proxy_instance_t *subproxy)
{ {
subproxy->alive = false; subproxy->alive = false;
@ -1241,7 +1243,7 @@ static bool parse_reconnect(proxy_instance_t *proxy, json_t *val)
ret = true; ret = true;
parent = proxy->parent; parent = proxy->parent;
disable_subproxy(gdata, parent, proxy); proxy->disabled = true;
if (parent != proxy) { if (parent != proxy) {
/* If this is a subproxy we only need to create a new one if /* If this is a subproxy we only need to create a new one if
* the url has changed. Otherwise automated recruiting will * the url has changed. Otherwise automated recruiting will
@ -1606,7 +1608,7 @@ static void drop_proxy(gdata_t *gdata, const char *buf)
return; return;
} }
LOGNOTICE("Generator asked to drop proxy %d:%d", id, subid); LOGNOTICE("Generator asked to drop proxy %d:%d", id, subid);
disable_subproxy(gdata, proxy, subproxy); subproxy->disabled = true;
} }
static void stratifier_reconnect_client(ckpool_t *ckp, const int64_t id) static void stratifier_reconnect_client(ckpool_t *ckp, const int64_t id)
@ -1844,7 +1846,7 @@ static void send_json_msgq(gdata_t *gdata, cs_msg_t **csmsgq)
csmsg->len = 0; csmsg->len = 0;
LOGNOTICE("Proxy %d:%d %s failed to send msg in send_json_msgq, dropping", LOGNOTICE("Proxy %d:%d %s failed to send msg in send_json_msgq, dropping",
proxy->id, proxy->subid, proxy->url); proxy->id, proxy->subid, proxy->url);
disable_subproxy(gdata, proxy->parent, proxy); proxy->disabled = true;
} }
csmsg->ofs += ret; csmsg->ofs += ret;
csmsg->len -= ret; csmsg->len -= ret;
@ -2523,12 +2525,12 @@ static void *proxy_recv(void *arg)
subproxy->id, subproxy->subid, cs->buf); subproxy->id, subproxy->subid, cs->buf);
} }
} }
if (cs)
cksem_post(&cs->sem);
/* Process hangup only after parsing messages */ /* Process hangup only after parsing messages */
if (hup) if (hup || subproxy->disabled)
disable_subproxy(gdata, proxi, subproxy); disable_subproxy(gdata, proxi, subproxy);
if (cs)
cksem_post(&cs->sem);
} }
return NULL; return NULL;
@ -2651,10 +2653,8 @@ static void *userproxy_recv(void *arg)
cksem_post(&cs->sem); cksem_post(&cs->sem);
} }
if (hup) { if (hup || proxy->disabled)
disable_subproxy(gdata, proxy->parent, proxy); disable_subproxy(gdata, proxy->parent, proxy);
continue;
}
} }
return NULL; return NULL;
} }
@ -2980,7 +2980,6 @@ static void parse_ableproxy(gdata_t *gdata, const int sockd, const char *buf, bo
if (disable) { if (disable) {
/* Set disabled bool here in case this is a parent proxy */ /* Set disabled bool here in case this is a parent proxy */
proxy->disabled = true; proxy->disabled = true;
disable_subproxy(gdata, proxy, proxy);
} else } else
reconnect_proxy(proxy); reconnect_proxy(proxy);
out: out:

Loading…
Cancel
Save