diff --git a/src/CONST.ts b/src/CONST.ts index 0a262d868de9..e98a42c973cf 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -737,6 +737,7 @@ const CONST = { MAX_RETRY_WAIT_TIME_MS: 10 * 1000, PROCESS_REQUEST_DELAY_MS: 1000, MAX_PENDING_TIME_MS: 10 * 1000, + MAX_REQUEST_RETRIES: 10, }, DEFAULT_TIME_ZONE: {automatic: true, selected: 'America/Los_Angeles'}, DEFAULT_ACCOUNT_DATA: {errors: null, success: '', isLoading: false}, diff --git a/src/libs/Network/SequentialQueue.js b/src/libs/Network/SequentialQueue.js index e53515fb5e87..5c74f791e073 100644 --- a/src/libs/Network/SequentialQueue.js +++ b/src/libs/Network/SequentialQueue.js @@ -86,7 +86,14 @@ function process() { RequestThrottle.clear(); return process(); } - return RequestThrottle.sleep().then(process); + return RequestThrottle.sleep() + .then(process) + .catch(() => { + Onyx.update(requestToProcess.failureData); + PersistedRequests.remove(requestToProcess); + RequestThrottle.clear(); + return process(); + }); }); return currentRequest; } diff --git a/src/libs/RequestThrottle.ts b/src/libs/RequestThrottle.ts index d6ccab91bf23..00dca2ebf61e 100644 --- a/src/libs/RequestThrottle.ts +++ b/src/libs/RequestThrottle.ts @@ -2,9 +2,11 @@ import CONST from '../CONST'; import {generateRandomInt} from './NumberUtils'; let requestWaitTime = 0; +let requestRetryCount = 0; function clear() { requestWaitTime = 0; + requestRetryCount = 0; } function getRequestWaitTime() { @@ -21,7 +23,13 @@ function getLastRequestWaitTime() { } function sleep(): Promise { - return new Promise((resolve) => setTimeout(resolve, getRequestWaitTime())); + requestRetryCount++; + return new Promise((resolve, reject) => { + if (requestRetryCount <= CONST.NETWORK.MAX_REQUEST_RETRIES) { + return setTimeout(resolve, getRequestWaitTime()); + } + return reject(); + }); } export {clear, getRequestWaitTime, sleep, getLastRequestWaitTime};