1
0
Fork 0
mirror of synced 2026-06-05 12:48:19 +00:00

fix: maxRetry hit infinite loop with negative input

This commit is contained in:
peterwoodworth 2023-08-11 16:24:09 -07:00
commit 7f4507af3c
No known key found for this signature in database
GPG key ID: 01931412FD685922
5 changed files with 30 additions and 5 deletions

2
dist/cleanup/index.js generated vendored
View file

@ -17699,7 +17699,7 @@ async function retryAndBackoff(fn, isRetryable, maxRetries = 12, retries = 0, ba
// It's retryable, so sleep and retry. // It's retryable, so sleep and retry.
await sleep(Math.random() * (Math.pow(2, retries) * base)); await sleep(Math.random() * (Math.pow(2, retries) * base));
retries += 1; retries += 1;
if (retries === maxRetries) { if (retries >= maxRetries) {
throw err; throw err;
} }
return await retryAndBackoff(fn, isRetryable, maxRetries, retries, base); return await retryAndBackoff(fn, isRetryable, maxRetries, retries, base);

7
dist/index.js generated vendored
View file

@ -363,7 +363,7 @@ async function retryAndBackoff(fn, isRetryable, maxRetries = 12, retries = 0, ba
// It's retryable, so sleep and retry. // It's retryable, so sleep and retry.
await sleep(Math.random() * (Math.pow(2, retries) * base)); await sleep(Math.random() * (Math.pow(2, retries) * base));
retries += 1; retries += 1;
if (retries === maxRetries) { if (retries >= maxRetries) {
throw err; throw err;
} }
return await retryAndBackoff(fn, isRetryable, maxRetries, retries, base); return await retryAndBackoff(fn, isRetryable, maxRetries, retries, base);
@ -451,7 +451,10 @@ async function run() {
const unsetCurrentCredentials = unsetCurrentCredentialsInput.toLowerCase() === 'true'; const unsetCurrentCredentials = unsetCurrentCredentialsInput.toLowerCase() === 'true';
const disableRetryInput = core.getInput('disable-retry', { required: false }) || 'false'; const disableRetryInput = core.getInput('disable-retry', { required: false }) || 'false';
const disableRetry = disableRetryInput.toLowerCase() === 'true'; const disableRetry = disableRetryInput.toLowerCase() === 'true';
const maxRetries = parseInt(core.getInput('retry-max-attempts', { required: false })) || 12; let maxRetries = parseInt(core.getInput('retry-max-attempts', { required: false })) || 12;
if (maxRetries < 1) {
maxRetries = 1;
}
for (const managedSessionPolicy of managedSessionPoliciesInput) { for (const managedSessionPolicy of managedSessionPoliciesInput) {
managedSessionPolicies.push({ arn: managedSessionPolicy }); managedSessionPolicies.push({ arn: managedSessionPolicy });
} }

View file

@ -124,7 +124,7 @@ export async function retryAndBackoff<T>(
// It's retryable, so sleep and retry. // It's retryable, so sleep and retry.
await sleep(Math.random() * (Math.pow(2, retries) * base)); await sleep(Math.random() * (Math.pow(2, retries) * base));
retries += 1; retries += 1;
if (retries === maxRetries) { if (retries >= maxRetries) {
throw err; throw err;
} }
return await retryAndBackoff(fn, isRetryable, maxRetries, retries, base); return await retryAndBackoff(fn, isRetryable, maxRetries, retries, base);

View file

@ -44,7 +44,10 @@ export async function run() {
const unsetCurrentCredentials = unsetCurrentCredentialsInput.toLowerCase() === 'true'; const unsetCurrentCredentials = unsetCurrentCredentialsInput.toLowerCase() === 'true';
const disableRetryInput = core.getInput('disable-retry', { required: false }) || 'false'; const disableRetryInput = core.getInput('disable-retry', { required: false }) || 'false';
const disableRetry = disableRetryInput.toLowerCase() === 'true'; const disableRetry = disableRetryInput.toLowerCase() === 'true';
const maxRetries = parseInt(core.getInput('retry-max-attempts', { required: false })) || 12; let maxRetries = parseInt(core.getInput('retry-max-attempts', { required: false })) || 12;
if (maxRetries < 1) {
maxRetries = 1;
}
for (const managedSessionPolicy of managedSessionPoliciesInput) { for (const managedSessionPolicy of managedSessionPoliciesInput) {
managedSessionPolicies.push({ arn: managedSessionPolicy }); managedSessionPolicies.push({ arn: managedSessionPolicy });
} }

View file

@ -632,6 +632,25 @@ describe('Configure AWS Credentials', () => {
expect(core.setFailed).toHaveBeenCalledWith('Could not assume role with OIDC: '); expect(core.setFailed).toHaveBeenCalledWith('Could not assume role with OIDC: ');
}); });
test('max retries negative input does not retry', async () => {
process.env['GITHUB_ACTIONS'] = 'true';
process.env['ACTIONS_ID_TOKEN_REQUEST_TOKEN'] = 'test-token';
jest.spyOn(core, 'getInput').mockImplementation(
mockGetInput({
'role-to-assume': ROLE_ARN,
'aws-region': FAKE_REGION,
'retry-max-attempts': '-1',
})
);
mockedSTS.reset();
mockedSTS.on(AssumeRoleWithWebIdentityCommand).rejects();
await run();
expect(mockedSTS.commandCalls(AssumeRoleWithWebIdentityCommand).length).toEqual(1);
expect(core.setFailed).toHaveBeenCalledWith('Could not assume role with OIDC: ');
});
test('role external ID provided', async () => { test('role external ID provided', async () => {
jest jest
.spyOn(core, 'getInput') .spyOn(core, 'getInput')