-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Lazy services are not shared #27756
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
I didn't manage to reproduce following the description. Would you be able to provide a repository with a reproducer? |
Same here. I cannot reproduce this on a minimal Symfony 3.4.12 project. https://github.com/dmaicher/skeleton/blob/lazy-services/config/services.yaml#L30 Service is lazy and I always get the same instance. |
Also, what's the output of |
Below is my composer show result, Im going to install a bare version of SF to see as well:
|
For more information, on my current installation, I created a bare service with nothing inside, then I try to get that service several times like this
The _constructor is called more than once, I went to the generated proxy cache file, put in my debug code:
And my debug backtrace looks like this:
If getName is called 5 times then the above backtrace will be printed out 5 times. For some reason the function was triggered with lazyLoad = false more than once? (I formatted the code a bit to remove sensitive information) |
You mean that the stack trace is exactly the same five times? That would be weird as I don't see why your kernel should handle five requests. I think it would still help a lot if you could create a small example application that would allow to reproduce the issue. |
I tracked it down to this single file that is causing the issue: src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php If I simply use the whole source of 3.4.12 with the ProxyDumper.php from 3.4.11 then it works. I did this simple test:
Now everything runs correctly. As you can see, the first scenario my service was put inside $this->privates, the second one it is put inside $this->services, there was no other change in my code or configs. PS: I'm trying to setup a test application to re-produce the issue, but so far I haven't been able to re-produce the issue yet unless I use it on my exact dev env. I suspect the issue is with either my code or a 3rd party plugin, but I haven't been able to nail it down yet. So far I know the latest change in ProxyDumper causes the issue, probably in combination with some issue from my code. |
@nicolas-grekas related to #27593 |
Indeed. Fixed in #27776. |
… (nicolas-grekas) This PR was merged into the 3.4 branch. Discussion ---------- [ProxyManagerBridge] Fix support of private services (bis) | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27756 | License | MIT | Doc PR | - Commits ------- 3ca0c86 [ProxyManagerBridge] Fix support of private services (bis)
add symfony 3.4.12 as conflicting version, because of symfony/symfony#27756, which cause bug #165
Symfony version(s) affected: 3.4.12
Description
I'm not sure if this is intentional or a new issue that has just come up, but it seems like any service that is declared as lazy is not shared anymore.
How to reproduce
Declare any service as lazy and then call it more than once any where, you will see that it is initialized more than once (__construct is called many times)
This issue happens today after I updated my code.
Edit: I tested on a very class with nothing but the __construct and another simple method, I can confirm that this happens on my current installation. If further checking is needed I can try with a barebone installation of Symfony.
The text was updated successfully, but these errors were encountered: