diff --git a/packages/nx/src/tasks-runner/cache.ts b/packages/nx/src/tasks-runner/cache.ts index d5efced66e..da59cbdb98 100644 --- a/packages/nx/src/tasks-runner/cache.ts +++ b/packages/nx/src/tasks-runner/cache.ts @@ -555,17 +555,20 @@ function tryAndRetry(fn: () => Promise): Promise { let attempts = 0; // Generate a random number between 2 and 4 to raise to the power of attempts const baseExponent = Math.random() * 2 + 2; + const baseTimeout = 15; const _try = async () => { try { attempts++; return await fn(); } catch (e) { - // Max time is 5 * 4^3 = 20480ms + // Max time is 15 * (4 + 4² + 4³ + 4⁴ + 4⁵) = 20460ms if (attempts === 6) { // After enough attempts, throw the error throw e; } - await new Promise((res) => setTimeout(res, baseExponent ** attempts)); + await new Promise((res) => + setTimeout(res, baseTimeout * baseExponent ** attempts) + ); return await _try(); } };