Skip to content

fix: break circular reference cycles#3268

Merged
stobrien89 merged 3 commits into
aws:masterfrom
smilkuri:fix-memory-leak
May 1, 2026
Merged

fix: break circular reference cycles#3268
stobrien89 merged 3 commits into
aws:masterfrom
smilkuri:fix-memory-leak

Conversation

@smilkuri

@smilkuri smilkuri commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available:
#1273

Description of changes:
PresignUrlMiddleware and EndpointDiscoveryMiddleware hold a direct $client reference back to the AwsClient through its HandlerList, creating a circular reference cycle that PHP's refcounting cannot collect. Replace $client with \WeakReference in both classes. The client outlives its own handler chain, so the weak reference resolves for the lifetime of the middleware.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@smilkuri smilkuri marked this pull request as ready for review April 9, 2026 18:32

@stobrien89 stobrien89 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution- just two comments. I led you down the most invasive path

Comment thread src/PresignUrlMiddleware.php
Comment thread src/EndpointDiscovery/EndpointDiscoveryMiddleware.php

@stobrien89 stobrien89 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @smilkuri, looks good. Before merging, we'll need you to push up a changelog entry, which goes in .changes/nextrelease- you'll need to create the nextrelease dir. There you'll need to create a json file of any name (e.g. fix-memory-leak.json) with the following structure:

[
    {
        "type": "enhancement",
        "category": "",
        "description": "<description_of_changes>"
    }
]

The reason we'll use a blank namespace for this is because when empty, the category field defaults to the Aws namespace, which is the most appropriate here because the changes apply to two unrelated classes.

@stobrien89

Copy link
Copy Markdown
Member

Thanks for the contribution, @smilkuri! :shipit:

@stobrien89 stobrien89 merged commit c33d17e into aws:master May 1, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants