Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S3 ListParts pagination infinite loop #3679

Merged
merged 5 commits into from
Jun 7, 2024

Conversation

landonxjames
Copy link
Contributor

Motivation and Context

The paginator for the S3 ListParts operation could loop forever: awslabs/aws-sdk-rust#1143. This is because most paginated operations use an empty next token as an indication that pagination is exhausted. ListParts instead sets the final next token as 0 causing the pagination to loop back to the first page and loop forever. Instead of an empty next token ListParts uses IsTruncated = false to indicate that pagination has been exhausted.

Description

  • Added a new trait isTruncatedPaginatorTrait
  • Add that trait to the S3 ListPartsOutput shape
  • Use the presence of that trait to vary the logic setting the is_empty value in the paginator.
    • If the trait is absent it looks for an empty next token as always
    • if the trait is present the value is set based on the value of the response's is_truncated field

Testing

  • Added integration test confirming that pagination terminates when a response contains is_truncated = false

Note: I'm still working on turning this into a model test rather than an S3 specific integration test, but I wanted to get some feedback on the actual fix while I'm figuring that out)

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@landonxjames landonxjames changed the title Landonxjames/list parts page Fix S3 ListParts pagination infinite loop Jun 3, 2024
Copy link

github-actions bot commented Jun 3, 2024

A new generated diff is ready to view.

A new doc preview is ready to view.

Adding new trait IsTruncatedPaginatorTrait that indicates the Paginator
should use the value of the isTruncated field to indicate if the
pagination has been exhausted.
@landonxjames landonxjames force-pushed the landonxjames/list-parts-page branch from d6b8de1 to 40a0381 Compare June 4, 2024 19:20
Copy link

github-actions bot commented Jun 4, 2024

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link

github-actions bot commented Jun 5, 2024

A new generated diff is ready to view.

A new doc preview is ready to view.

@landonxjames landonxjames force-pushed the landonxjames/list-parts-page branch from 62d4f62 to 3d73844 Compare June 5, 2024 22:04
Fixing up isTruncatedPaginator model test
@landonxjames landonxjames force-pushed the landonxjames/list-parts-page branch from 3d73844 to 901144e Compare June 5, 2024 22:12
Copy link

github-actions bot commented Jun 5, 2024

A new generated diff is ready to view.

A new doc preview is ready to view.

@landonxjames landonxjames marked this pull request as ready for review June 6, 2024 00:06
@landonxjames landonxjames requested review from a team as code owners June 6, 2024 00:06
Copy link
Contributor

@aajtodd aajtodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few things to consider but nothing blocking. Looks good overall.

rustTemplate(
"""
// Pagination is exhausted when `is_truncated` is false
let is_empty = !resp.is_truncated.unwrap_or(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This assumes the output shape member name is is_truncated which while likely true we could probably be more precise by having the trait include the member shape ID of the truncation member.

* In this case we use a false value of isTruncated as the only indicator that
* the pagination is exhausted.
* */
private fun isEmptySetter() =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wanted to go even more down the rabbit hole you could declare a section for this bit of code and then register a customization for that section that does something different. You would then basically be able to move all of this into a single TruncatedPaginatorDecorator that handles both the model transform and the actual codegen logic.

CHANGELOG.next.toml Outdated Show resolved Hide resolved
Copy link
Contributor

@ysaito1001 ysaito1001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the effort put into adding codegen tests!

Copy link

github-actions bot commented Jun 6, 2024

A new generated diff is ready to view.

A new doc preview is ready to view.

@landonxjames landonxjames added this pull request to the merge queue Jun 7, 2024
@landonxjames
Copy link
Contributor Author

Merging this for now to make sure it goes in with the next smithy-rs release since it fixes an actual customer bug. Going to connect with @aajtodd on Monday about the unaddressed suggestions to hopefully get those in as well.

Merged via the queue into main with commit 998af09 Jun 7, 2024
44 checks passed
@landonxjames landonxjames deleted the landonxjames/list-parts-page branch June 7, 2024 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants