Fix: Prevent infinite loop in IAM role policy listing #2122
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Prevent infinite loop in IAM role policy listing
Description
This PR fixes a potential infinite loop in getRoles when
ListRolePoliciesorListAttachedRolePoliciespagination fails.Previously, if an error occurred during pagination (e.g.,
NextPagereturns an error), the code would log the error andcontinue. This could cause the loop to retry indefinitely if the paginator state didn't advance, leading to a flood of error logs and a hung process.The fix replaces
continuewithbreak, ensuring that if a pagination error occurs for a specific role, we stop processing policies for that role and move on to the next role (or finish), preventing the infinite loop. This matches the behavior already present in getGroupPolicies.Infinite Loop Scenario: Role Deletion
A specific scenario where this infinite loop occurs is if a Role is deleted during the execution of Terraformer:
ListRolesretrieves a list of roles, includingRoleA.RoleA,RoleAis deleted from AWS (out of band).ListRolePolicies(orListAttachedRolePolicies) is called forRoleA.NoSuchEntityerror because the role no longer exists.continue.NextPageagain.Changes
continuewithbreakin getRoles forrolePoliciesPageloop.continuewithbreakin getRoles forroleAttachedPoliciesPageloop.Verification
go build ./providers/aws/....getGroupPolicies.