Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
EntityResolverManager instantiates objects unnecessarily which is super dangerous since router rebuild occur during kernel destruct event when many services become unavailable - eg. current_user which would currently cause a route rebuild to fail if the simpletest module is enabled since SimpletestResultsForm uses the cache_context service during its construction.
This is critical because router rebuild errors like this are hard to detect and test for.
Proposed resolution
Creating the objects is actually unnecessary since reflection will work just fine with class names.
Remaining tasks
Write patch
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#26 | 2300131.26-interdiff.txt | 1.75 KB | Berdir |
#26 | 2300131.26.patch | 14.11 KB | Berdir |
#19 | 2300131.19-interdiff.txt | 642 bytes | Berdir |
#19 | 2300131.19.patch | 14.08 KB | Berdir |
#17 | 2300131.16.patch | 14.08 KB | Berdir |
Comments
Comment #1
dawehnerYeah using the controller resolver probably won't work here then, we need to manually figure out which class we want to reflect against.
Comment #2
alexpottFirst attempt at a patch - we have a problem with the service:method notation...
From the patch. Otherwise it is totally possible to not actually construct the objects and use reflection to discover the entities to upcast.
Comment #3
alexpottPatch in #2 includes another patch :(
Comment #4
alexpottComment #5
dawehnerMaybe the class resolver could get a util to return a reflection object?
Comment #6
alexpottYeah I though about that... but that we would need to do that for the controller resolver too
Comment #7
dawehnerCould this even speed up the rebuilding process a bit?
Comment #8
dawehnerThough I think these are tasks for follow ups.
Comment #9
catchContrib and custom code is going to be interacting with route rebuilding as well, and the requirement not to instantiate objects isn't documented anywhere afaik.
Is there another place we could do the route rebuild (right before kernel destruct for example?) so it doesn't run into this problem? If there's a performance improvement we could also make this change, but doesn't look like the right fix to the actual problem.
Comment #10
alexpottSo the reason we have the problem is that we currently have a synthetic request service and the request scope - but this is removed in #2284103: Remove the request from the container. Once that is in I don't think we need to add a comment about anything.
In fact this patch makes the EntityResolver better by allowing the use of services in more places for entity resolving.
Comment #12
dawehnerInstanciating all the services was quite good to find all kind of triggered code during construction time but I don't think
we should actually use that problem as a feature.
Comment #16
BerdirRe-roll, let's see if that worked. Not sure if there anything else to do here?
Comment #17
BerdirA patch would help.
Comment #19
BerdirSo the unit test was actually failing on something valid, crazy stuff ;)
Comment #22
BerdirComment #23
alexpottFlipping the question around... @catch why should they expect their controllers to be instantiated during a route rebuild?
Comment #24
BerdirYes, I don't see how that would make sense either. We would have to document it if we wanted them to be called, but not the other way round...
Comment #25
dawehnerThis certainly was not the case in the earlier days of the routing system, this instantiation was done to be able to figure out
whether you wanted to upcast or not. The init. though was always just a pure implementation detail, if you ask me. The upcasting process certainly
worked without it.
We should explain that the container on runtime doesn't have that information.
Not for this issue but I wonder whether we could allow for special cases (route rebuilding) to able to fetch a containerBuilder instance which has that information. Maybe we could even dump a Builder container, in case if needed.
Comment #26
BerdirImproved those comments a bit.
Comment #27
dawehnerThis is good to go now.
Comment #28
catchCommitted/pushed to 8.0.x, thanks!