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

Memory Leak and Segfault (Exit Code 139) in Aws\ResultPaginator Due to Repeated Metrics Middleware Registration #3086

Closed
1 task done
iromanko opened this issue Feb 17, 2025 · 4 comments
Assignees
Labels
bug This issue is a bug. p1 This is a high priority issue potential-regression Marking this issue as a potential regression to be checked by team member queued This issues is on the AWS team's backlog

Comments

@iromanko
Copy link

iromanko commented Feb 17, 2025

Describe the bug

Starting from version 3.336.0, the Aws\ResultPaginator class continuously adds a metrics middleware each time it is instantiated. This leads to:
• An increasing function call stack over time in long-running processes.
• High memory consumption due to repeated middleware registrations.
• In some cases, PHP crashes with exit code 139 (segmentation fault).

Regression Issue

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

Expected Behavior

The Aws\ResultPaginator class should not repeatedly add the metrics middleware on each instantiation. Middleware should be registered once per client lifecycle or have a mechanism to prevent redundant additions.

Current Behavior

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2097152 bytes) in /srv/app/vendor/aws/aws-sdk-php/src/functions.php on line 67

Call Stack:
    0.0011     480264   1. {main}() /srv/app/reproducer.php:0
   10.3241  131880872   2. Aws\AwsClient->getIterator($name = 'Scan', $args = ['TableName' => 'test']) /srv/app/reproducer.php:13
   10.3243  131883568   3. Aws\ResultPaginator->search($expression = 'Items') /srv/app/vendor/aws/aws-sdk-php/src/AwsClientTrait.php:35

Reproduction Steps

Steps to reproduce the behavior:
1. Run a long-running script that continuously creates Aws\ResultPaginator instances.
2. Monitor memory usage and function call stack growth.
3. Eventually, PHP may crash with exit code 139.

$sdk = new Aws\Sdk([
    'region'  => 'us-east-2',
    'version' => 'latest',
]);

$dynamoDb = $sdk->createDynamoDb();

while (true) {
    $paginator = $dynamoDb->getIterator('Scan', ['TableName' => 'test']);
}

Possible Solution

A possible fix could involve checking if the middleware is already present before adding it again.

Additional Information/Context

Disabling the metrics middleware prevents the issue, confirming it as the root cause.

SDK version used

3.339.14

Environment details (Version of PHP (php -v)? OS name and version, etc.)

PHP 8.3.8

@iromanko iromanko added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 17, 2025
@github-actions github-actions bot added the potential-regression Marking this issue as a potential regression to be checked by team member label Feb 17, 2025
@yenfryherrerafeliz yenfryherrerafeliz added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels Feb 17, 2025
@yenfryherrerafeliz yenfryherrerafeliz self-assigned this Feb 17, 2025
@yenfryherrerafeliz yenfryherrerafeliz added p1 This is a high priority issue queued This issues is on the AWS team's backlog and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Feb 17, 2025
@yenfryherrerafeliz
Copy link
Contributor

Hi @iromanko, sorry for the inconvenient. The metrics implementation was adding named middlewares, however, our middleware handler list does not validate if a middleware was already appended in order to append a new middleware, and hence adding the same middleware multiple times. I have created this patch in order to prevent this behavior when appending the metrics middleware.

Thank you!

@stobrien89
Copy link
Member

Hi @iromanko,

I believe #3087 should fix this. Closing for now. Please let us know if you're still having issues after upgrading and testing.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@iromanko
Copy link
Author

@yenfryherrerafeliz @stobrien89 thanks for the quick fix! I’ve tested the update, and everything is working correctly now. Appreciate the fast response and support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p1 This is a high priority issue potential-regression Marking this issue as a potential regression to be checked by team member queued This issues is on the AWS team's backlog
Projects
None yet
Development

No branches or pull requests

3 participants