Skip to content

fix: break circular reference cycles from non-static closures#3282

Merged
stobrien89 merged 1 commit into
aws:masterfrom
smilkuri:fix/memory-leak-2
May 15, 2026
Merged

fix: break circular reference cycles from non-static closures#3282
stobrien89 merged 1 commit into
aws:masterfrom
smilkuri:fix/memory-leak-2

Conversation

@smilkuri
Copy link
Copy Markdown
Contributor

@smilkuri smilkuri commented May 6, 2026

Issue #, if available:
Related to #1273

Description of changes:
Seven middleware closures in the implicitly capture $this because they aren't declared static, creating circular references between the client and its HandlerList. Fixed by making closures static, extracting needed values into local variables and using WeakReference for the S3MultiRegionClient. Verified all 7 fixes by running the cyclic reference test script and all of them show 0 KB leaked and no cycles detected.

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 draft May 6, 2026 20:18
@smilkuri smilkuri force-pushed the fix/memory-leak-2 branch from 98199d8 to 884642b Compare May 6, 2026 20:20
@smilkuri smilkuri marked this pull request as ready for review May 6, 2026 20:31
Copy link
Copy Markdown
Member

@stobrien89 stobrien89 left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @smilkuri! I see you spotted an extra one in Middleware::mapRequest()- nice catch.

@stobrien89 stobrien89 force-pushed the fix/memory-leak-2 branch from 884642b to 7e80d7a Compare May 15, 2026 15:35
@stobrien89 stobrien89 merged commit 600202c into aws:master May 15, 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