feat: Improve debug logging in retry logic (#1485)

This commit is contained in:
Michał Pawlik
2025-09-11 20:22:18 +02:00
committed by kellertk
parent 1b22251287
commit 9aa437c71f
+15 -4
View File
@@ -185,15 +185,26 @@ export async function retryAndBackoff<T>(
return await fn(); return await fn();
} catch (err) { } catch (err) {
if (!isRetryable) { if (!isRetryable) {
core.debug(`retryAndBackoff: error is not retryable: ${errorMessage(err)}`);
throw err; throw err;
} }
// It's retryable, so sleep and retry. // It's retryable, so sleep and retry.
await sleep(Math.random() * (2 ** retries * base)); const delay = Math.random() * (2 ** retries * base);
retries += 1; const nextRetry = retries + 1;
if (retries >= maxRetries) {
core.debug(
`retryAndBackoff: attempt ${nextRetry} of ${maxRetries} failed: ${errorMessage(err)}. ` +
`Retrying after ${Math.floor(delay)}ms.`,
);
await sleep(delay);
if (nextRetry >= maxRetries) {
core.debug('retryAndBackoff: reached max retries; giving up.');
throw err; throw err;
} }
return await retryAndBackoff(fn, isRetryable, maxRetries, retries, base);
return await retryAndBackoff(fn, isRetryable, maxRetries, nextRetry, base);
} }
} }