Detect stratum outage based on either select timing out or receiving an empty buffer and properly re-establish connection by disabling the stratum_active flag, coping with empty buffers in parse_stratum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
diff --git a/cgminer.c b/cgminer.c
index c08cfe1..37eeda1 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4163,24 +4163,28 @@ static void *stratum_thread(void *userdata)
* every minute so if we fail to receive any for 2 minutes we
* assume the connection has been dropped and treat this pool
* as dead */
- if (select(pool->sock + 1, &rd, NULL, NULL, &timeout) < 1) {
+ select(pool->sock + 1, &rd, NULL, NULL, &timeout);
+ s = recv_line(pool);
+ if (!s) {
applog(LOG_INFO, "Stratum connection to pool %d interrupted", pool->pool_no);
pool->getfail_occasions++;
total_go++;
+ pool->stratum_active = false;
+ if (initiate_stratum(pool) && auth_stratum(pool))
+ continue;
+
pool_died(pool);
while (!initiate_stratum(pool) || !auth_stratum(pool)) {
if (pool->removed)
goto out;
- sleep(5);
+ sleep(30);
}
applog(LOG_INFO, "Stratum connection to pool %d resumed", pool->pool_no);
pool_resus(pool);
continue;
}
- s = recv_line(pool);
- if (unlikely(!s))
- continue;
+
if (!parse_method(pool, s) && !parse_stratum_response(s))
applog(LOG_INFO, "Unknown stratum msg: %s", s);
free(s);
diff --git a/util.c b/util.c
index d39d103..6d6409b 100644
--- a/util.c
+++ b/util.c
@@ -1103,6 +1103,9 @@ bool parse_method(struct pool *pool, char *s)
bool ret = false;
char *buf;
+ if (!s)
+ goto out;
+
val = JSON_LOADS(s, &err);
if (!val) {
applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);
@@ -1166,7 +1169,7 @@ bool auth_stratum(struct pool *pool)
sret = recv_line(pool);
if (!parse_method(pool, sret)) {
clear_sock(pool);
- applog(LOG_WARNING, "Failed to parse stratum buffer");
+ applog(LOG_INFO, "Failed to parse stratum buffer");
free(sret);
return ret;
}