From d0f557bbf89f60dfe9c6a45807954fe495c78ba8 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 14 Feb 2015 14:44:33 +1100 Subject: [PATCH] Handle reconnect message differently for parent proxy than child subproxies --- src/generator.c | 20 +++++++++++++------- src/stratifier.c | 13 ++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/generator.c b/src/generator.c index b3a6072a..fecf0895 100644 --- a/src/generator.c +++ b/src/generator.c @@ -105,6 +105,7 @@ struct proxy_instance { bool disabled; /* Subproxy no longer to be used */ bool reconnect; /* We need to drop and reconnect */ + bool reconnecting; /* Parsed reconnect, need to reconnect clients */ bool alive; pthread_mutex_t notify_lock; @@ -1805,13 +1806,17 @@ static void *proxy_recv(void *arg) /* Call this proxy dead to allow us to fail * over to a backup pool until the reconnect * pool is up */ - subproxy->reconnect = false; - alive = subproxy->alive = false; - send_proc(ckp->generator, "reconnect"); - LOGWARNING("Proxy %d:%s reconnect issue, dropping existing connection", - subproxy->id, subproxy->si->url); Close(cs->fd); - break; + subproxy->reconnect = false; + subproxy->reconnecting = true; + subproxy->alive = false; + if (parent_proxy(subproxy)) { + alive = false; + send_proc(ckp->generator, "reconnect"); + LOGWARNING("Proxy %d:%s reconnect issue, dropping existing connection", + subproxy->id, subproxy->si->url); + break; + } } continue; } @@ -1902,7 +1907,8 @@ reconnect: cproxy = best_proxy(ckp, gdata); if (!cproxy) goto out; - if (proxi != cproxy) { + if (proxi != cproxy || cproxy->reconnecting) { + cproxy->reconnecting = false; proxi = cproxy; if (!ckp->passthrough) { connsock_t *cs = proxi->cs; diff --git a/src/stratifier.c b/src/stratifier.c index a78be6c7..76e86c2a 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1102,16 +1102,14 @@ static proxy_t *subproxy_by_id(sdata_t *sdata, const int id, const int subid) } /* Iterates over all clients in proxy mode and sets the reconnect bool for the - * message to be sent lazily next time they speak to us if they're not bound - * to the requested proxy id */ -static void reconnect_clients_to(sdata_t *sdata, const int id) + * message to be sent lazily next time they speak to us */ +static void reconnect_clients(sdata_t *sdata) { stratum_instance_t *client, *tmp; ck_rlock(&sdata->instance_lock); HASH_ITER(hh, sdata->stratum_instances, client, tmp) { - if (client->proxyid != id) - client->reconnect = true; + client->reconnect = true; } ck_runlock(&sdata->instance_lock); } @@ -1269,7 +1267,7 @@ static void update_notify(ckpool_t *ckp, const char *cmd) * clients now to reconnect since we have enough information to * switch. */ proxy->notified = true; - reconnect_clients_to(sdata, id); + reconnect_clients(sdata); } LOGINFO("Broadcast updated stratum notify"); stratum_broadcast_update(dsdata, new_block | clean); @@ -1913,7 +1911,8 @@ static char *stratifier_stats(ckpool_t *ckp, sdata_t *sdata) } /* Sets the currently active proxy. Clients will be told to reconnect once the - * first notify data comes from this proxy. */ + * first notify data comes from this proxy. Even if we are already bound to + * this proxy we are only given this message if all clients must move. */ static void set_proxy(sdata_t *sdata, const char *buf) { proxy_t *proxy;