Problem/Motivation
Since #2913912: URL generator may have a stale route provider during module installation installing the admin_toolbar_tools module (part of https://www.drupal.org/project/admin_toolbar) is causing the route builder to throw a \RuntimeException('Recursive router rebuild detected.');
. This is then caught by \Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber::menuLinksRebuild()
and the error is logged but basically eaten. The recursive rebuild occurs because the lazy route provider is still injected into \Drupal\Core\Menu\LocalTaskManager which has been instantiated due to the plugin cache clearer.
Here is the corresponding bug report in the admin_toolbar module - #2926844: admin_toolbar_tools is not creating links on Appearance, Extend and People when installed.
Proposed resolution
It seems as though there are two options:
Completely rebuild the container yet again before calling\Drupal::service('router.builder')->rebuild();
in the ModuleInstaller- Add flag to lazy route provider to ensure it does not cause recursive rebuilds. This is the only solution that prevents recursive rebuilds if anything causes a route rebuild during a hook_install() after admin_toolbar_tools has been installed.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#16 | 2930715-2-16.patch | 4.92 KB | alexpott |
Comments
Comment #2
alexpottn/a
Comment #3
alexpottHere's a fix that works and might be good for any rebuild that occurs during a module install once admin_toolbar_tools is installed. Now to write a test.
Comment #4
alexpottHere's a test that shows the problem and proves that the fix fixes it.
Comment #7
mlncn CreditAttribution: mlncn at Agaric for Drutopia, National Institute for Children's Health Quality commentedPending agreement by the testbot, this resolves the admin_toolbar_tools problem we faced on fresh site installation and allows it to install correctly on its own also.
Comment #8
alexpottI discussed this issue with @dawehner - it was at his suggestion that I tried using the routing events to overcome the problem. Using events does introduce a slight brittleness since there is no way to say ensure my event goes first or last as we need here - hence the priorities of 3000 and -3000. The other alternatives are adding a method to the route builder to return the value of
\Drupal\Core\Routing\RouteBuilder::$building
which might be more robust but it requires an API addition to \Drupal\Core\Routing\RouteBuilderInterface.@dawehner and I also briefly discussed having a completely different container during module install with an alternate implementation of RouteBuilder that also protects itself against recursive route rebuilding. I feel that this might cause more problems than it solves because of having alternate containers that are only active during module install is likely to lead to increased complexity of install time not less - which should be the aim.
It would be great if @dawehner also gave his +1 due to his deep understanding of both module install and the routing system.
Comment #10
alexpottDrupalCI error
Comment #12
chr.fritschTestbot hickup
Comment #13
dawehnerIt would be nice to mention on possible case where this can happen. One question which could be answered: Why does this recursive rebuild happens on install time, but not on runtime.
Comment #14
acbramley CreditAttribution: acbramley at PreviousNext for Transport for NSW commentedThis also fixes the same problem when enabling the workbench_moderation module.
Comment #15
alexpottIt doesn't happen on runtime because the service has the old route provider injected - not a lazy one that rebuilds on demand. The fresh route provider is only available the next request in regular runtime. Module install is unfortunately exceptionally special.
Added more docs as per #13.
Comment #16
alexpottOops forgot to rebase.
Comment #17
dawehnerThank you @alexpott for adding another round of helpful docs.
Comment #19
catchCommitted 0d2a45a and pushed to 8.5.x. Thanks!
Comment #21
catchAnd.. cherry-picked to 8.4.x. Via @alexpott as well as the error getting logged "Also without the patch modules like admin_toolbar_extra won't create all their links until a cache rebuild - see https://www.drupal.org/project/admin_toolbar/issues/2926844"