Skip to content

Bug: Log buffer would run an infinite loop when the size of the log is exactly the same as the maxBytes size specified. #4737

@fidelisojeah

Description

@fidelisojeah

Expected Behavior

It should not keep attempting to remove from the log buffer (if it's currently empty).

Current Behavior

It keeps attempting to remove from the buffer even if the buffer is empty.

There are checks to make sure that the item size is less than or equal to the maximum size however, subsequent checks check that the item size + buffer size is less than the maximum size.

So in an execution where:
maxBytes is 20000
item size is 20000
buffer size is 0

there would be an infinite loop because while it attempts to remove from the map.

if item size was greater than item size, it would have thrown an error instead.

Code snippet

link to code:

https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/logger/src/logBuffer.ts#L135

Steps to Reproduce

  1. Enable buffered logs
  2. get log data that would be exactly same as the maxBytes specified

Possible Solution

Either check that the item size is definitely less than max bytes (not less than or equal)
or only attempt to remove from the buffer if there is something in the buffer

while (buffer.currentBytesSize + item.byteSize >= this.#maxBytesSize && buffer.currentBytesSize) {

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

22.x

Packaging format used

npm

Execution logs

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompletedThis item is complete and has been merged/shipped

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions