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: Create request object per-page in getPaginatedResults(...) #536

Conversation

lgarber-akamai
Copy link
Contributor

📝 Description

This PR fixes a bug that would cause corrupt/partially overridden data to be returned from endpoint methods that implement getPaginatedResults[T any](...) and have a large number of results.

This issue occurred because Resty's request objects are not designed to be executed multiple times. Specifically, the internal Request.Result pointer (initialized by us using SetResult(...)) is not implicitly reset when executing a request multiple times, leading to new data being written on top of existing data.

✔️ How to Test

Unit Testing

make testunit

Manual Testing

Excluding manual testing steps for now since it requires a large number of resources (~ >200).

@lgarber-akamai lgarber-akamai added the bugfix for any bug fixes in the changelog. label Jun 27, 2024
@lgarber-akamai lgarber-akamai requested a review from a team as a code owner June 27, 2024 14:00
@lgarber-akamai lgarber-akamai requested review from yec-akamai and ezilber-akamai and removed request for a team June 27, 2024 14:00
@@ -161,6 +165,8 @@ func TestRequestHelpers_delete(t *testing.T) {
}

func TestRequestHelpers_paginateAll(t *testing.T) {
const totalResults = 4123
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this much larger and uneven to reproduce the failure case before applying the fix


// This request object cannot be reused for each page request
// because it can lead to possible data corruption
req := client.R(ctx).SetResult(resultType)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another potential solution could've been to call req.SetResult(...) at the beginning of this function but I wasn't 100% sure that wouldn't have unintended side-effects

Copy link
Contributor

@ezilber-akamai ezilber-akamai left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

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

Nice fix! Tests passed locally.

@lgarber-akamai lgarber-akamai merged commit f166457 into linode:main Jun 28, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix for any bug fixes in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants