-
Notifications
You must be signed in to change notification settings - Fork 974
Fix stackoverflow with large pages in paginator #6668
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
Conversation
Previously, signalig onNext() to the subscriber was done via recursion, pulling elements from an iterator over the current page returned by the service. However, this can quickly lead to a stackoverflow error since the stack will grow linearly with the size of the page. This commit fixes this issue by using SdkPublisher's builtin flatMapIterable(), which uses a loop to signal onNext(), and also ensures that it does not call itself recursively. fixes #6411
fa2b2c7 to
c40873e
Compare
| public static final Function<Integer, Iterator<Integer>> EMPTY_ITERATOR = response -> new ArrayList<Integer>().listIterator(); | ||
| @Mock | ||
| AsyncPageFetcher asyncPageFetcher; | ||
| PaginatedItemsPublisher<Integer, Integer> itemsPublisher; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this test is just testing features of SdkPublisher such as limit(), not PaginatedItemsPublisher itself, so just removed this class entirely
...gen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/AsyncResponseClassSpec.java
Show resolved
Hide resolved
...ed-classes-test/src/test/java/software/amazon/awssdk/services/paginators/PaginatorsTest.java
Outdated
Show resolved
Hide resolved
...n/awssdk/codegen/poet/paginators/PaginatedOperationWithResultKeyAndMoreResultsPublisher.java
Show resolved
Hide resolved
|
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |



Previously, signalig onNext() to the subscriber was done via recursion, pulling elements from an iterator over the current page returned by the service. However, this can quickly lead to a stackoverflow error since the stack will grow linearly with the size of the page.
This commit fixes this issue by using SdkPublisher's builtin flatMapIterable(), which uses a loop to signal onNext(), and also ensures that it does not call itself recursively.
fixes #6411
Motivation and Context
Modifications
Testing
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License