From dd22d73145142925300ef4b51344844d2169e82f Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 24 Feb 2015 11:25:01 +1100 Subject: [PATCH] Do not switch more clients than we have headroom --- src/stratifier.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 0caeab51..8e9f2343 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1163,7 +1163,8 @@ static void reconnect_clients(sdata_t *sdata) HASH_ITER(hh, sdata->stratum_instances, client, tmpclient) { if (client->proxyid == proxy->id) continue; - headroom--; + if (--headroom < 0) + break; reconnects++; if (client->reconnect) reconnect_client(sdata, client); @@ -1177,7 +1178,8 @@ static void reconnect_clients(sdata_t *sdata) proxy->id); if (headroom < 42) generator_recruit(sdata->ckp); - } + } else if (headroom < 0) + generator_recruit(sdata->ckp); } static proxy_t *current_proxy(sdata_t *sdata) @@ -2251,7 +2253,8 @@ static void dead_proxy(sdata_t *sdata, const char *buf) HASH_ITER(hh, sdata->stratum_instances, client, tmp) { if (client->proxyid != id || client->subproxyid != subid) continue; - headroom--; + if (--headroom < 0) + break; reconnects++; if (client->reconnect) reconnect_client(sdata, client); @@ -2265,7 +2268,8 @@ static void dead_proxy(sdata_t *sdata, const char *buf) id, subid); if (headroom < 42) generator_recruit(sdata->ckp); - } + } else if (headroom < 0) + generator_recruit(sdata->ckp); } /* Must hold a reference */