From aa23506ac2d372047746ace06069aa75a3ea6f61 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Thu, 29 Jan 2015 13:48:08 +1100 Subject: [PATCH] Delete killed clients after a minute in case we have missed dangling references --- src/stratifier.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index bc548e8c..443e844b 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -264,6 +264,7 @@ struct stratum_instance { time_t last_txns; /* Last time this worker requested txn hashes */ time_t disconnected_time; /* Time this instance disconnected */ + time_t died_time; int64_t suggest_diff; /* Stratum client suggested diff */ double best_diff; /* Best share found by this instance */ @@ -915,6 +916,7 @@ static void update_base(ckpool_t *ckp, int prio) static void __add_dead(sdata_t *sdata, stratum_instance_t *client) { + client->died_time = time(NULL); DL_APPEND(sdata->dead_instances, client); sdata->stats.dead++; sdata->dead_generated++; @@ -1432,13 +1434,15 @@ static void drop_client(sdata_t *sdata, int64_t id) /* Cull old unused clients lazily when there are no more reference * counts for them. */ DL_FOREACH_SAFE(sdata->dead_instances, client, tmp) { - if (!client->ref) { - killed++; - __del_dead(sdata, client); - dealloc(client->workername); - dealloc(client->useragent); - dealloc(client); - } + if (now_t - client->died_time < 60) + continue; + if (unlikely(client->ref)) + continue; + killed++; + __del_dead(sdata, client); + free(client->workername); + free(client->useragent); + free(client); } ck_wunlock(&sdata->instance_lock);