diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-09-26 18:00:21 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-09-26 18:00:26 +0200 |
commit | 211e8c25d52644552cb37531cdb637f4f12c8782 (patch) | |
tree | 1ba56cb19a88b5dc9cbc4950b4814d84128ab3db /lib/wallet/wallet.ts | |
parent | c89c90b7fa69b030c82f8cc73a29f89987016250 (diff) |
fix bug in retrying logic for reserve status
Diffstat (limited to 'lib/wallet/wallet.ts')
-rw-r--r-- | lib/wallet/wallet.ts | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/wallet/wallet.ts b/lib/wallet/wallet.ts index 32b85e7b0..ffd57e201 100644 --- a/lib/wallet/wallet.ts +++ b/lib/wallet/wallet.ts @@ -612,8 +612,7 @@ export class Wallet { * First fetch information requred to withdraw from the reserve, * then deplete the reserve, withdrawing coins until it is empty. */ - private processReserve(reserveRecord: any): void { - let retryDelayMs = 100; + private processReserve(reserveRecord: any, retryDelayMs: number = 250): void { const opId = "reserve-" + reserveRecord.reserve_pub; this.startOperation(opId); this.updateExchangeFromUrl(reserveRecord.exchange_base_url) @@ -633,11 +632,10 @@ export class Wallet { return Query(this.db).put("history", depleted).finish(); }) .catch((e) => { - console.error("Failed to deplete reserve"); - console.error(e); - setTimeout(() => this.processReserve(reserveRecord), retryDelayMs); - // exponential backoff truncated at one minute - retryDelayMs = Math.min(retryDelayMs * 2, 1000 * 60); + // random, exponential backoff truncated at 3 minutes + let nextDelay = Math.min(2 * retryDelayMs + retryDelayMs * Math.random(), 3000 * 60); + console.warn(`Failed to deplete reserve, trying again in ${retryDelayMs} ms`); + setTimeout(() => this.processReserve(reserveRecord, nextDelay), retryDelayMs); }); } |