Skip to content

Commit

Permalink
Fix infinite loop on cloudwatchlogs GetLogEventsPages
Browse files Browse the repository at this point in the history
Cloudwatch log event responses always include the next token and pagination
will never terminate.
  • Loading branch information
johanneswuerbach committed Apr 22, 2018
1 parent eed0e84 commit d5a4da3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion aws/request/request_pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Pagination struct {
NewRequest func() (*Request, error)

started bool
prevTokens []interface{}
nextTokens []interface{}

err error
Expand All @@ -49,7 +50,7 @@ type Pagination struct {
//
// Will always return true if Next has not been called yet.
func (p *Pagination) HasNextPage() bool {
return !(p.started && len(p.nextTokens) == 0)
return !(p.started && (len(p.nextTokens) == 0 || awsutil.DeepEqual(p.nextTokens, p.prevTokens)))
}

// Err returns the error Pagination encountered when retrieving the next page.
Expand Down Expand Up @@ -96,6 +97,7 @@ func (p *Pagination) Next() bool {
return false
}

p.prevTokens = p.nextTokens
p.nextTokens = req.nextPageTokens()
p.curPage = req.Data

Expand Down
5 changes: 5 additions & 0 deletions aws/request/request_pagination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ func TestPagination_Standalone(t *testing.T) {
testCase{aws.String("SecondValue"), aws.String("FirstToken"), aws.String("SecondToken")},
testCase{aws.String("ThirdValue"), aws.String("SecondToken"), aws.String("")},
},
{
testCase{aws.String("FirstValue"), aws.String("InitalToken"), aws.String("FirstToken")},
testCase{aws.String("SecondValue"), aws.String("FirstToken"), aws.String("SecondToken")},
testCase{nil, aws.String("SecondToken"), aws.String("SecondToken")},
},
}

for _, c := range cases {
Expand Down
4 changes: 2 additions & 2 deletions service/s3/s3manager/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func TestBatchDeleteList(t *testing.T) {
Key: aws.String("1"),
},
},
NextMarker: aws.String("marker"),
NextMarker: aws.String("1stMarker"),
IsTruncated: aws.Bool(true),
},
{
Expand All @@ -477,7 +477,7 @@ func TestBatchDeleteList(t *testing.T) {
Key: aws.String("2"),
},
},
NextMarker: aws.String("marker"),
NextMarker: aws.String("2ndMarker"),
IsTruncated: aws.Bool(true),
},
{
Expand Down

0 comments on commit d5a4da3

Please sign in to comment.