-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Memory leak when using route annotation #32220
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
Comments
Well, your no-leak case is actually using more than 2x the memory from the start, so maybe it leaked everything even faster (and then stopped leaking more)... |
That is just because the first command warms up the cache |
I have committed right now a warmup command too https://travis-ci.org/goetas/symfony-mem-leak/jobs/551321942 |
Tacked down the issue to the Replacing it with a |
I have reduced it to a minimal version that leaks on my machine, but does not on travis. |
Found the issue... https://bugs.php.net/bug.php?id=76982 😭 PhpFilesAdapter uses exactly this technique to load files from the cache |
I think symfony's |
Introduced in symfony with #27543 (but it is a PHP bug rather than symfony) |
Thanks for the details, I found a work around in #32236 |
Can somebody with the right privileges change the label on this issue from "routing" to "cache"? |
Unfortunately it seems the PHP bug (https://bugs.php.net/bug.php?id=76982) has opened some pandora box of memory leaks.... Here (build and code) the same type of memory leak applied to the symfony dependency injection container... that recently started to use closures and includes quite intensively. Can somebody prove me wrong please? |
This PR was merged into the 4.2 branch. Discussion ---------- [Cache] work aroung PHP memory leak | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32220 | License | MIT | Doc PR | - Works around https://bugs.php.net/76982, as identified by @goetas in the linked issue. Commits ------- 5d55b91 [Cache] work aroung PHP memory leak
I had a look at your reproducers, my opinion right now is that we don't care: to hit the bug, one needs to create a container instance in a loop. This is not a realistic use case to me: the container should be booted once and reused as often as possible. That's what php-pm and similar strategies do. Swoole integrations should too if they don't. |
In this case (with non shared services), the leak happens with one single instance on the container already booted. I understand that in this case symfony can not do much, it is more a general PHP issue. |
I don't see any memory leak with this case. |
You are right... I got lot in the last hours of debugging. It seems the issue is only when creating multiple containers. Things not common in PHP-FPM applications, but a common thing for lambda, swoole or reactphp
I'm not testing memory usage, but memory leaks. It does not matter now much memory is using, it should not increase on each iteration. But that is another topic |
If that's true, that's a bug in the integration of SF with those: the same kernel is reused in e.g. php-pm, which does it correctly, using reactphp. I think we can close this issue, thanks again for investigating! |
I agree that this can be closed. Hope just that somebody will start to work on https://bugs.php.net/bug.php?id=76982 I think that there is a lot of RAM world-wide just because of that bug 😃 |
I am using https://github.com/k911/swoole-bundle and didn't notice memory leaks in production mode, dev does have some but not a big problem. Do you know how to replicate memory leak under swoole? |
I do not know how you handle requests in swoole. Regarding the cache issue, it was introduced with symfony 4.2, if you have an older version, you are safe from this too |
Symfony version(s) affected: v4.3.2 (tested also 3.4 and 4.2, same issue)
Description
When a route is defined using annotations, there is a memory leak.
If the route is defined using YAML, there is no memory leak.
How to reproduce
I have created a basic symfony app available in https://github.com/goetas/symfony-mem-leak
The travis build showing the memory leak https://travis-ci.org/goetas/symfony-mem-leak/jobs/551313488
The test app has a basic controller as follows:
Requests to
leak
will result in a memory leak, requests tonoleak
will have no leaks.The repo includes 2 scripts
bin/runner-no-leak
andbin/runner-no-leak
that call 5000 times the two routes.When
bin/runner-leak
is called, memory goes up.In larger application memory goes up faster... apparently depending on the output of the method..
The text was updated successfully, but these errors were encountered: