-
-
Notifications
You must be signed in to change notification settings - Fork 471
Fix Entity manager is closed on worker mode and PHP 8.4 #1903
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
Fix Entity manager is closed on worker mode and PHP 8.4 #1903
Conversation
78a0944
to
086f7f7
Compare
Maybe instead of checking with 3 different ways whether the service is lazy, we could obtain that information from the service definition? |
fbf1e6a
to
8bbaf52
Compare
Unfortunately there is no way to detect if object itself is natively lazy. It's not possible to detect it at service container compile time by reading the container definition either. But, we can use the version of the Symfony DI bundle to determine if the lazy services are represented as lazy native objects, because since version 7.3 that's exactly the case. Prior version 7.3 the lazy services are I reconsidered the usage of After analyzing the changes between 7.2 and 7.3 for: symfony/dependency-injection 7.2-7.3 diff I think it's best to check if the following method exists in order to determine if symfony version is >= 7.3:
Then: For PHP < 8.4 or symfony < 7.3 the logic remains as is: if ((! $manager instanceof LazyLoadingInterface && ! $manager instanceof LazyObjectInterface) || $manager->isOpen()) {
$manager->clear();
return;
}
$this->resetManager($managerName); Else: $r = new ReflectionClass($manager);
if ($r->isUninitializedLazyObject($manager)) {
return;
}
if ($manager->isOpen()) {
$manager->clear();
return;
}
$this->resetManager($managerName); |
5a369d8
to
a162d8e
Compare
I'm confused… isn't that exactly what https://www.php.net/manual/de/reflectionclass.isuninitializedlazyobject.php is supposed to achieve? |
IIRC it only checks if it's lazy uninitialized object. If it's initialized then you are out of luck. |
Yes, that's correct.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on a bigger project with multiple entity managers and FrankenPHP.
Consecutive requests to the same worker now don't result in "The EntityManager is closed." exceptions any more.
Fixes #1896
related to symfony/symfony/#61005