From fc71cb1b493a5181d0b574b6c086a4fc16453e88 Mon Sep 17 00:00:00 2001 From: TheBestPessimist Date: Wed, 20 Sep 2017 11:00:02 +0300 Subject: [PATCH] Compute the next backoff value before using it --- src/duplicacy_gcdstorage.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/duplicacy_gcdstorage.go b/src/duplicacy_gcdstorage.go index fcd784e..b04ac23 100644 --- a/src/duplicacy_gcdstorage.go +++ b/src/duplicacy_gcdstorage.go @@ -108,16 +108,17 @@ func (storage *GCDStorage) shouldRetry(threadIndex int, err error) (bool, error) return false, err } - delay := storage.backoffs[threadIndex]*rand.Float64() + storage.backoffs[threadIndex]*rand.Float64() - LOG_INFO("GCD_RETRY", "Thread: %03d. Message: %s. Retrying after %.2f seconds. current backoff: %.2f. Number of retries: %d", threadIndex, message, delay, storage.backoffs[threadIndex], storage.backoffsRetries[threadIndex]) - time.Sleep(time.Duration(delay * float64(time.Second))) - if storage.backoffs[threadIndex] < LIMIT_BACKOFF_TIME { storage.backoffs[threadIndex] *= 2.0 } else { storage.backoffs[threadIndex] = LIMIT_BACKOFF_TIME storage.backoffsRetries[threadIndex] += 1 } + + delay := storage.backoffs[threadIndex]*rand.Float64() + storage.backoffs[threadIndex]*rand.Float64() + LOG_INFO("GCD_RETRY", "Thread: %03d. Message: %s. Retrying after %.2f seconds. Current backoff: %.2f. Number of retries: %d", threadIndex, message, delay, storage.backoffs[threadIndex], storage.backoffsRetries[threadIndex]) + time.Sleep(time.Duration(delay * float64(time.Second))) + return true, nil }