Retry should get_work() fail for whatever reason.
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
diff --git a/main.c b/main.c
index 51b230f..95f9b7f 100644
--- a/main.c
+++ b/main.c
@@ -778,16 +778,18 @@ static bool get_work(struct work *work, bool queued)
struct thr_info *thr = &thr_info[0];
struct work *work_heap;
bool ret = false;
+ int failures = 0;
+retry:
if (unlikely(!queued && !queue_request())) {
- applog(LOG_ERR, "Failed to queue_request in get_work");
+ applog(LOG_WARNING, "Failed to queue_request in get_work");
goto out;
}
/* wait for 1st response, or get cached response */
work_heap = tq_pop(thr->q, NULL);
if (unlikely(!work_heap)) {
- applog(LOG_ERR, "Failed to tq_pop in get_work");
+ applog(LOG_WARNING, "Failed to tq_pop in get_work");
goto out;
}
dec_queued();
@@ -797,6 +799,15 @@ static bool get_work(struct work *work, bool queued)
ret = true;
free(work_heap);
out:
+ if (unlikely(ret == false)) {
+ if ((opt_retries >= 0) && (++failures > opt_retries)) {
+ applog(LOG_ERR, "Failed %d times to get_work");
+ return ret;
+ }
+ applog(LOG_WARNING, "Retrying after %d seconds", opt_fail_pause);
+ sleep(opt_fail_pause);
+ goto retry;
+ }
return ret;
}