Skip to content

Commit

Permalink
fix(core): decrease attempts/overall max allowable time
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Mar 22, 2024
1 parent 2aa906c commit 41a4009
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/nx/src/tasks-runner/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,20 @@ export class Cache {

private tryAndRetry<T>(fn: () => Promise<T>): Promise<T> {
let attempts = 0;
const baseTimeout = 100;
const baseTimeout = 5;
// Generate a random number between 2 and 4 to raise to the power of attempts
const baseExponent = Math.random() * 2 + 2;
const _try = async () => {
try {
attempts++;
return await fn();
} catch (e) {
if (attempts === 10) {
// Max time is 5 * 4^3 = 20480ms
if (attempts === 6) {
// After enough attempts, throw the error
throw e;
}
await new Promise((res) =>
setTimeout(res, baseTimeout * baseExponent ** attempts)
);
await new Promise((res) => setTimeout(res, baseExponent ** attempts));
return await _try();
}
};
Expand Down

0 comments on commit 41a4009

Please sign in to comment.