Skip to content

[HttpKernel] Avoid memory leaks cache attribute, profiler listener #60934

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

Open
wants to merge 3 commits into
base: 7.4
Choose a base branch
from

Conversation

andrew-demb
Copy link
Contributor

@andrew-demb andrew-demb commented Jun 28, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

For the current moment, if the onKernelTerminate / onKernelResponse methods won't be called, the listener's state won't be reset between requests.

Please let me know if this should be considered as a new feature - to retarget PR to the 7.3 branch

Similar to PR #60933

@carsonbot carsonbot added this to the 6.4 milestone Jun 28, 2025
@andrew-demb andrew-demb changed the title [HttpKernel.] Avoid memory leaks cache attribute listener [HttpKernel] Avoid memory leaks cache attribute listener Jun 28, 2025
@andrew-demb andrew-demb force-pushed the avoid-memory-leaks-cache-attribute branch from a3367a0 to 5996644 Compare June 28, 2025 00:51
@andrew-demb
Copy link
Contributor Author

CI failure is unrelated

There was 1 failure:

1) Symfony\Bundle\FrameworkBundle\Tests\Functional\CachePoolsTest::testCachePools
Failed asserting that true is false.

@nicolas-grekas
Copy link
Member

Introducing an new method means this is a new feature, it should target 7.4

@andrew-demb andrew-demb force-pushed the avoid-memory-leaks-cache-attribute branch from 5996644 to 2e51bdc Compare June 28, 2025 11:50
@andrew-demb andrew-demb changed the base branch from 6.4 to 7.4 June 28, 2025 11:51
@andrew-demb andrew-demb force-pushed the avoid-memory-leaks-cache-attribute branch from 2e51bdc to a7c7c72 Compare June 28, 2025 11:53
@andrew-demb andrew-demb changed the title [HttpKernel] Avoid memory leaks cache attribute listener [HttpKernel] Avoid memory leaks cache attribute, profiler listener Jun 28, 2025
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.4 Jun 29, 2025
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Works for me but did you actually experience this leak?

@@ -129,8 +130,7 @@ public function onKernelTerminate(TerminateEvent $event): void
$this->profiler->saveProfile($this->profiles[$request]);
}

$this->profiles = new \SplObjectStorage();
$this->parents = new \SplObjectStorage();
$this->reset();
Copy link
Member

Choose a reason for hiding this comment

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

we don't need this call then, since reset is going to be called anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just trying to preserve the old logic.
I'll drop it if it's not necessary then

@andrew-demb
Copy link
Contributor Author

Works for me but did you actually experience this leak?

I have a Swoole+Symfony application with memory leak and while investigating the reasons (the memory profiler didn't help with the root cause) I found a possible memory leak in 3rd party library that relies on "kernel.response" event for cleanup (instead of tagging with kernel.reset) and this event is not called in all situations.

This prompted me to look for similar potential issues in Symfony so I created this PR to prevent similar issues in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy