summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-10-10 15:08:01 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-10-15 10:27:05 -0300
commite9a0a71480a7455637c4bf82b57b3c90d76196ce (patch)
tree782f26ce16e4ba3ddc360268a655003bb00faf6e
parent030bcadd239f67ef60f9736506304cd33f86ba85 (diff)
downloadmullvadvpn-e9a0a71480a7455637c4bf82b57b3c90d76196ce.tar.xz
mullvadvpn-e9a0a71480a7455637c4bf82b57b3c90d76196ce.zip
Retry account data fetch if it fails
-rw-r--r--gui/packages/desktop/src/renderer/app.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/gui/packages/desktop/src/renderer/app.js b/gui/packages/desktop/src/renderer/app.js
index aa20035555..fe66980c6b 100644
--- a/gui/packages/desktop/src/renderer/app.js
+++ b/gui/packages/desktop/src/renderer/app.js
@@ -662,6 +662,8 @@ type AccountFetchWatcher = {
class AccountDataCache {
_currentAccount: ?AccountToken;
_expiresAt: ?Date;
+ _fetchAttempt: number;
+ _fetchRetryTimeout: ?TimeoutID;
_fetch: (AccountToken) => Promise<AccountData>;
_update: (?AccountData) => void;
_watchers: Array<AccountFetchWatcher>;
@@ -670,6 +672,7 @@ class AccountDataCache {
this._fetch = fetch;
this._update = update;
this._watchers = [];
+ this._fetchAttempt = 0;
}
fetch(accountToken: AccountToken, watcher?: AccountFetchWatcher) {
@@ -692,6 +695,12 @@ class AccountDataCache {
}
invalidate() {
+ if (this._fetchRetryTimeout) {
+ clearTimeout(this._fetchRetryTimeout);
+ this._fetchRetryTimeout = null;
+ this._fetchAttempt = 0;
+ }
+
this._expiresAt = null;
this._update(null);
this._notifyWatchers((watcher) => watcher.onError(new Error('Cancelled')));
@@ -720,7 +729,22 @@ class AccountDataCache {
} catch (error) {
if (this._currentAccount === accountToken) {
this._notifyWatchers((watcher) => watcher.onError(error));
+ this._scheduleRetry(accountToken);
}
+ }
+ }
+
+ _scheduleRetry(accountToken: AccountToken) {
+ this._fetchAttempt += 1;
+
+ const delay = Math.min(2048, 1 << (this._fetchAttempt + 2)) * 1000;
+
+ log.debug(`Failed to fetch account data. Retrying in ${delay} ms`);
+
+ this._fetchRetryTimeout = setTimeout(() => {
+ this._fetchRetryTimeout = null;
+ this._performFetch(accountToken);
+ }, delay);
}
_notifyWatchers(notify: (AccountFetchWatcher) => void) {