Description
Describe the bug
client-cloudwatch-logs.paginateGetLogEvents seemingly paginates forever.
Your environment
SDK version number
@aws-sdk/client-cloudwatch-logs@3.56.0
Is the issue in the browser/Node.js/ReactNative?
Node.js
Details of the browser/Node.js/ReactNative version
v14.18.1
Steps to reproduce
const pConfig = {
client: this.client,
};
const startTime = Date.UTC(2022, 2, 23, 22, 40, 0);
const endTime = Date.UTC(2022, 2, 23, 22, 50, 0);
const args = {
logGroupName,
logStreamName,
startTime,
endTime,
};
const paginator = paginateGetLogEvents(pConfig, args);
let promises = [];
try {
// FYI This is where the pagination never terminates
for await (const page of paginator) {
if (page.events.length > 0) {
promises.push(this.writeLog(page.events, logGroupName, logStreamName));
}
await new Promise(resolve => setTimeout(resolve, 100));
}
} catch (e) {
reject(e);
}
Observed behavior
paginateGetLogEvents paginates for a very long time, so long that I've never witnessed it completing. My last test run was that it paginated 14000+ times and had to manually be stopped.
Expected behavior
It should stop paginating fairly quickly. Even if LogsEvents spanned many days, weeks or months (they don't since the LogStream is a fairly small period) it seems like cloudwatch should be able to have a sensible way of determining beginning and ending times.
Screenshots
Additional context
I have a single LogGroup and a Single LogStream with a grand total of 11 LogEvents. The above code finds the 11 LogEvents quickly. No matter what starttime and endtime I use it doesn't change the behavior. What's odd is that the nextBackwardToken and nextForwardToken ids do not change at least when it reaches the never ending pagination. I suspect the library should identify this state between nextBackwardToken and nextForwardToken equality and then stop terminate pagination. Doesn't appear to be doing that. I don't know if there is something else under the hood that identifies when to stop pagination. I've used other paginate aws-sdk methods and they never experience this behavior.
EDIT
I updated the code to narrow the starttime and endtimes. I also uploaded a screenshot. Cleaned up code.