Commit 56eee5f007ed6fd6caf14bdf5c78ea91e3a47c00

Con Kolivas 2011-07-06T13:16:47

Retry should get_work() fail for whatever reason.

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;
 }