From cc3e6214d41548a694f8f574b253c832910c3a55 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 10 May 2018 14:47:45 +1000 Subject: [PATCH] Close sockets on disabled proxies as well when setting them to disable. --- src/generator.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/generator.c b/src/generator.c index 01d4be7b..f018a04b 100644 --- a/src/generator.c +++ b/src/generator.c @@ -1163,6 +1163,13 @@ static void close_proxy_socket(proxy_instance_t *proxy, proxy_instance_t *subpro } } +/* Set the disabled bool and close the socket */ +static void set_proxy_disabled(proxy_instance_t *proxy) +{ + proxy->disabled = true; + close_proxy_socket(proxy->parent, proxy); +} + /* 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 * dereference. This will only disable subproxies so parent proxies need to @@ -1243,7 +1250,7 @@ static bool parse_reconnect(proxy_instance_t *proxy, json_t *val) ret = true; parent = proxy->parent; - proxy->disabled = true; + set_proxy_disabled(proxy); if (parent != proxy) { /* If this is a subproxy we only need to create a new one if * the url has changed. Otherwise automated recruiting will @@ -1608,7 +1615,7 @@ static void drop_proxy(gdata_t *gdata, const char *buf) return; } LOGNOTICE("Generator asked to drop proxy %d:%d", id, subid); - subproxy->disabled = true; + set_proxy_disabled(subproxy); } static void stratifier_reconnect_client(ckpool_t *ckp, const int64_t id) @@ -1816,7 +1823,7 @@ struct cs_msg { /* Sends all messages in the queue ready to be dispatched, leaving those that * would block to be handled next pass */ -static void send_json_msgq(gdata_t *gdata, cs_msg_t **csmsgq) +static void send_json_msgq(cs_msg_t **csmsgq) { cs_msg_t *csmsg, *tmp; int ret; @@ -1846,7 +1853,7 @@ static void send_json_msgq(gdata_t *gdata, cs_msg_t **csmsgq) csmsg->len = 0; LOGNOTICE("Proxy %d:%d %s failed to send msg in send_json_msgq, dropping", proxy->id, proxy->subid, proxy->url); - proxy->disabled = true; + set_proxy_disabled(proxy); } csmsg->ofs += ret; csmsg->len -= ret; @@ -1917,7 +1924,7 @@ static void *proxy_send(void *arg) mutex_unlock(&gdata->psend_lock); if (!msg) { - send_json_msgq(gdata, &csmsgq); + send_json_msgq(&csmsgq); continue; } @@ -1981,7 +1988,7 @@ static void *proxy_send(void *arg) "method", "mining.submit"); } add_json_msgq(&csmsgq, subproxy, &val); - send_json_msgq(gdata, &csmsgq); + send_json_msgq(&csmsgq); } return NULL; } @@ -2979,7 +2986,7 @@ static void parse_ableproxy(gdata_t *gdata, const int sockd, const char *buf, bo } if (disable) { /* Set disabled bool here in case this is a parent proxy */ - proxy->disabled = true; + set_proxy_disabled(proxy); } else reconnect_proxy(proxy); out: