Score:0

How to deal with "Recursive router rebuild detected." exception error

ke flag

I am frequently seeing module installation and uninstallation fail with the error

Uncaught PHP Exception RuntimeException: "Recursive router rebuild detected." at /path/to/drupal/web/core/lib/Drupal/Core/Routing/RouteBuilder.php line 121

It seems the underlying problem is that something goes wrong, and the way that the error is handled tries to get router information that is already being changed.

Is the fact that it's producing this fatal WSOD exception a core bug? Or is this one of those things where they will always pass responsibility to whatever is causing the original error? Is there a good way to diagnose these problems?

It leaves the modules half-installed, like with entity types registered but no schema. It's not great.

An example error:

The website encountered an unexpected error. Please try again later.

RuntimeException: Recursive router rebuild detected. in Drupal\Core\Routing\RouteBuilder->rebuild() (line 121 of core/lib/Drupal/Core/Routing/RouteBuilder.php).
Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild() (Line: 67)
Drupal\Core\Routing\RouteProviderLazyBuilder->getRouteProvider() (Line: 104)
Drupal\Core\Routing\RouteProviderLazyBuilder->getRoutesByPattern() (Line: 115)
Drupal\devel\EntityTypeInfo->getPathParts() (Line: 100)
Drupal\devel\EntityTypeInfo->setEntityTypeLinkTemplate() (Line: 75)
Drupal\devel\EntityTypeInfo->entityTypeAlter() (Line: 94)
devel_entity_type_alter() (Line: 539)
Drupal\Core\Extension\ModuleHandler->alter() (Line: 334)
Drupal\Core\Plugin\DefaultPluginManager->alterDefinitions() (Line: 127)
Drupal\Core\Entity\EntityTypeManager->findDefinitions() (Line: 175)
Drupal\Core\Plugin\DefaultPluginManager->getDefinitions() (Line: 22)
Drupal\Core\Plugin\DefaultPluginManager->getDefinition() (Line: 136)
Drupal\Core\Entity\EntityTypeManager->getDefinition() (Line: 257)
Drupal\Core\Entity\EntityTypeManager->getHandler() (Line: 196)
Drupal\Core\Entity\EntityTypeManager->getStorage() (Line: 497)
Drupal\Core\Entity\EntityBase::loadMultiple() (Line: 19)
Drupal\ggroup\Routing\SubgroupRouteProvider->getRoutes()
call_user_func() (Line: 146)
Drupal\Core\Routing\RouteBuilder->rebuild() (Line: 83)
Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild() (Line: 67)
Drupal\Core\Routing\RouteProviderLazyBuilder->getRouteProvider() (Line: 104)
Drupal\Core\Routing\RouteProviderLazyBuilder->getRoutesByPattern() (Line: 115)
Drupal\devel\EntityTypeInfo->getPathParts() (Line: 100)
Drupal\devel\EntityTypeInfo->setEntityTypeLinkTemplate() (Line: 75)
Drupal\devel\EntityTypeInfo->entityTypeAlter() (Line: 94)
devel_entity_type_alter() (Line: 539)
Drupal\Core\Extension\ModuleHandler->alter() (Line: 334)
Drupal\Core\Plugin\DefaultPluginManager->alterDefinitions() (Line: 127)
Drupal\Core\Entity\EntityTypeManager->findDefinitions() (Line: 175)
Drupal\Core\Plugin\DefaultPluginManager->getDefinitions() (Line: 22)
Drupal\Core\Plugin\DefaultPluginManager->getDefinition() (Line: 136)
Drupal\Core\Entity\EntityTypeManager->getDefinition() (Line: 257)
Drupal\Core\Entity\EntityTypeManager->getHandler() (Line: 196)
Drupal\Core\Entity\EntityTypeManager->getStorage() (Line: 247)
Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber->onEntityTypeDelete() (Line: 51)
Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber->onEntityTypeEvent()
call_user_func() (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 145)
Drupal\Core\Entity\EntityTypeListener->onEntityTypeDelete() (Line: 167)
Drupal\Core\Entity\EntityDefinitionUpdateManager->uninstallEntityType() (Line: 490)
Drupal\Core\Extension\ModuleInstaller->uninstall() (Line: 91)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->uninstall() (Line: 174)
Drupal\system\Form\ModulesUninstallConfirmForm->submitForm()
call_user_func_array() (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 592)
Drupal\Core\Form\FormBuilder->processForm() (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 708)
Drupal\Core\DrupalKernel->handle() (Line: 19)
4uk4 avatar
cn flag
Can you post a full error message with a stack trace?
ke flag
You can see from bugs like [#2351353](https://www.drupal.org/project/drupal/issues/2351353) and [#2930715](https://www.drupal.org/project/drupal/issues/2930715) that different problems cause the original error. Supposedly it was "fixed", I am just wondering how people usually handle it.
cn flag
Looks like it's the devel module triggering the error (at least at this iteration) - can you uninstall that module or do you just end up in the same loop?
4uk4 avatar
cn flag
The two issues mentioned is one very early core bug from 2014 and one from a contrib module from 2017, both fixed. In your case the culprit is the devel module, though, `Drupal\devel\EntityTypeInfo->getPathParts` is calling a route rebuild twice. And this is caused by two different modules Ggroup and Views invoking by some unlucky coincidence the devels alter hook multiple times.
ke flag
should RouteProviderLazyBuilder set its own rebuilding flag before it tries to do the rebuild?
ke flag
ha, i uninstalled devel and now i get Symfony\Component\Routing\Exception\RouteNotFoundException: Route "devel.admin_settings" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 206 of core/lib/Drupal/Core/Routing/RouteProvider.php).
4uk4 avatar
cn flag
The fact that the route builder is run through a lazy-built proxy class doesn't matter. I would get rid of Ggroup first. This module doesn't work with Devel, in my opinion. It tries to derive routes from entities for which the entity type info is not yet discovered and devel is hooking into the entity type discovery to do its own thing before the routes are built.
miststudent2011 avatar
fr flag
By any chance did you apply patch from issue [#2726209](https://www.drupal.org/project/devel/issues/2726209#comment-13573873) if yes, remove the patch and try again. It will most probably solve your issue.
ke flag
Hmm. I had been using that patch but I removed it from composer in addition to adding some hacks to RouteProviderLazyBuilder. Too many changes at once. It does seem like removing that patch is sufficient in itself. I think Devel needs to add something there to prevent this.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.