Skip to content

Commit 97ef425

Browse files
authored
feat: Improve debug logging in retry logic (#1485)
1 parent 6bf1557 commit 97ef425

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/helpers.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,26 @@ export async function retryAndBackoff<T>(
185185
return await fn();
186186
} catch (err) {
187187
if (!isRetryable) {
188+
core.debug(`retryAndBackoff: error is not retryable: ${errorMessage(err)}`);
188189
throw err;
189190
}
190191
// It's retryable, so sleep and retry.
191-
await sleep(Math.random() * (2 ** retries * base));
192-
retries += 1;
193-
if (retries >= maxRetries) {
192+
const delay = Math.random() * (2 ** retries * base);
193+
const nextRetry = retries + 1;
194+
195+
core.debug(
196+
`retryAndBackoff: attempt ${nextRetry} of ${maxRetries} failed: ${errorMessage(err)}. ` +
197+
`Retrying after ${Math.floor(delay)}ms.`,
198+
);
199+
200+
await sleep(delay);
201+
202+
if (nextRetry >= maxRetries) {
203+
core.debug('retryAndBackoff: reached max retries; giving up.');
194204
throw err;
195205
}
196-
return await retryAndBackoff(fn, isRetryable, maxRetries, retries, base);
206+
207+
return await retryAndBackoff(fn, isRetryable, maxRetries, nextRetry, base);
197208
}
198209
}
199210

0 commit comments

Comments
 (0)