Skip to content

Commit

Permalink
Merge pull request #28365 from dukenv0307/fix/27886
Browse files Browse the repository at this point in the history
Add max retry request
  • Loading branch information
puneetlath authored Oct 4, 2023
2 parents 24aa7c1 + fb093ec commit 538e272
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
9 changes: 8 additions & 1 deletion src/libs/Network/SequentialQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 9 additions & 1 deletion src/libs/RequestThrottle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -21,7 +23,13 @@ function getLastRequestWaitTime() {
}

function sleep(): Promise<void> {
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};

0 comments on commit 538e272

Please sign in to comment.