Skip to content

Infinite Pagination in cloudwatchlogs.NewGetLogEventsPaginator() #2958

Closed as not planned
@osmontero

Description

@osmontero

Acknowledgements

Describe the bug

When paginating through CloudWatch Logs events via cloudwatchlogs.NewGetLogEventsPaginator(), the end of the log stream is not properly detected. Instead, the final page of the result set is continually requested in an infinite loop.

The problem is that the GetLogEvents API signals the end of the stream by setting nextForwardToken or nextBackwardToken to the same as the requested value (and not null, like most other paginated APIs). GetLogEventsPaginator evaluates if the nextToken is null instead of evaluating if it is equal, resulting in an infinity loop.

Image

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

HasMorePages() must return false if there are no more pages

Current Behavior

HasMorePages() always returns true

Reproduction Steps

paginator := cloudwatchlogs.NewGetLogEventsPaginator(cwl, &cloudwatchlogs.GetLogEventsInput{
  LogGroupName:  aws.String(logGroup),
  LogStreamName: aws.String(stream),
  StartTime:     aws.Int64(startTime.Unix() * 1000),
  EndTime:       aws.Int64(endTime.Unix() * 1000),
  StartFromHead: aws.Bool(true),
})

for paginator.HasMorePages() {
  page, err := paginator.NextPage(ctx)
  if err != nil {
    return nil, catcher.Error("cannot get logs", err, nil)
  }
  
  for _, event := range page.Events {
    transformedLogs = append(transformedLogs, *event.Message)
  }
}

More details can be found here: main.go

Possible Solution

evaluate if the nextForwardToken is equal to the requested params.NextToken

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

github.com/aws/aws-sdk-go-v2 v1.32.8
github.com/aws/aws-sdk-go-v2/config v1.28.11
github.com/aws/aws-sdk-go-v2/credentials v1.17.52

Compiler and Version used

go1.23.4 linux/amd64

Operating System and version

Debian Bookworm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions