Problem/Motivation
Hello,
After the upgrade from Drupal 10.2.7 to 10.3.3, I got this error when I tried to login to BO
The website encountered an unexpected error. Try again later.
Error: Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '512' frames in Drupal\Core\Cache\Context\CacheContextsManager->optimizeTokens() (line 164 of core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php).
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys() (Line: 242)
Drupal\Core\Cache\VariationCache->createCacheIdFast() (Line: 173)
Drupal\Core\Cache\VariationCache->getRedirectChain() (Line: 35)
Drupal\Core\Cache\VariationCache->get() (Line: 80)
Drupal\Core\Session\AccessPolicyProcessor->processAccessPolicies() (Line: 23)
Drupal\Core\Session\PermissionChecker->hasPermission() (Line: 129)
Drupal\Core\Session\UserSession->hasPermission() (Line: 121)
Drupal\Core\Session\AccountProxy->hasPermission() (Line: 154)
Drupal\Core\Access\AccessResult::allowedIfHasPermissions() (Line: 43)
Drupal\user\Access\PermissionAccessCheck->access()
call_user_func_array() (Line: 160)
Drupal\Core\Access\AccessManager->performCheck() (Line: 136)
Drupal\Core\Access\AccessManager->check() (Line: 93)
Drupal\Core\Access\AccessManager->checkNamedRoute() (Line: 106)
Drupal\system\Access\SystemAdminMenuBlockAccessCheck->hasAccessToChildMenuItems() (Line: 79)
Drupal\system\Access\SystemAdminMenuBlockAccessCheck->access()
call_user_func_array() (Line: 160)
Drupal\Core\Access\AccessManager->performCheck() (Line: 136)
Drupal\Core\Access\AccessManager->check() (Line: 93)
Drupal\Core\Access\AccessManager->checkNamedRoute() (Line: 106)
Drupal\system\Access\SystemAdminMenuBlockAccessCheck->hasAccessToChildMenuItems() (Line: 79)
Drupal\system\Access\SystemAdminMenuBlockAccessCheck->access()
call_user_func_array() (Line: 160)
Drupal\Core\Access\AccessManager->performCheck() (Line: 136)
Drupal\Core\Access\AccessManager->check() (Line: 93)
Drupal\Core\Access\AccessManager->checkNamedRoute() (Line: 106)
Drupal\system\Access\SystemAdminMenuBlockAccessCheck->hasAccessToChildMenuItems() (Line: 79)
Drupal\system\Access\SystemAdminMenuBlockAccessCheck->access()
call_user_func_array() (Line: 160)
Drupal\Core\Access\AccessManager->performCheck() (Line: 136)
Drupal\Core\Access\AccessManager->check() (Line: 93)
Drupal\Core\Access\AccessManager->checkNamedRoute() (Line: 106)
Drupal\system\Access\SystemAdminMenuBlockAccessCheck->hasAccessToChildMenuItems() (Line: 79)
Drupal\system\Access\SystemAdminMenuBlockAccessCheck->access()
call_user_func_array() (Line: 160)Steps to reproduce
Create a menu link where the route_name and parent_name are the same.
mymodule.admin:
title: Administrative Users
route_name: system.admin
weight: 0
parent: system.admin
Proposed resolution
Remaining tasks
Add a test
Review
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Any idea about how to fix it please ?
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | core-system-admin-menu-block-access-check-infinite-recursion.patch | 1.92 KB | boychev |
Issue fork drupal-3473554
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
cilefen commentedIn the short-term have you tried turning xdebug off? Are there any core patches installed on the site?
Comment #3
cilefen commentedThis could be the same as #3371010: Aggregation changes in 10.1 break xdebug.
Comment #4
enimae1 commentedI don't have any core patches, and I tried to turning xdebug off but I got probably the same error :
Comment #5
cilefen commentedCan you check on what error is logged there?
Comment #6
cilefen commentedAlso please get the entire stack trace.
Comment #7
enimae1 commentedyou can find below the entire log error
Comment #8
cilefen commentedWhich core and contributed modules are installed in this site and what are their versions?
Comment #9
vensiresI experience the same issue in a website with Drupal 10.3, Groups 3.2.x, Flexible Permissions 1.x and VariationCache 8.x-1.5.
If I disable XDebug, I then really receive a WSOD with no error I could track.
If I modify
\Drupal\system\Access\SystemAdminMenuBlockAccessCheck::access()so that::hasAccessToChildMenuItems()is not called, it works.@enimae1, might you have the same setup?
Comment #10
vensiresAdded issue which might be related. It was created to fix #296693: Restrict access to empty top level administration pages and is the last change in the SystemAdminMenuBlockAccessCheck.php file.
Comment #12
vensiresAdding patch from current MR as a quick fix.
Comment #13
vensiresSeems I was too fast to blame the previous issue or my set of contrib modules installed.
In a custom module I had the following
mymodule.links.menu.ymlfile:Having the same parent and route_name is not necessarily bad in logic but does cause the recursion in SystemAdminMenuBlockAccessCheck::hasAccessToChildMenuItems() seen above.
@enimae1, might you have have something related in your own installation?
Comment #14
tcrawford commentedWe had the same issue on a project. The above hint was very helpful. Thank you.
I wonder if the menu item recursion should not be checked during a cache clear to prevent such configurations getting into production.
Comment #15
quietone commentedI'm doing triage on issues assigned to the maintenance minor.
@vensires, thanks for providing steps to reproduce. In the future, that should be added to the issue summary to help all contributors, reviewers and committers.
Using those steps to reproduce I verified that this fails on 11.x.
Comment #16
quietone commentedComment #17
mstrelan commentedWe could probably add recursion detection / prevention to
\Drupal\system\Access\SystemAdminMenuBlockAccessCheck::access. This access check is currently tested in\Drupal\Tests\system\Functional\Menu\MenuAccessTest::testSystemAdminMenuBlockAccessCheck. We should add another test case there for this recursion. See alsomenu_test.routing.ymlandmenu_test.links.menu.yml.Comment #19
boychev commentedAttaching a recursion guard approach (static $visiting[]) for Drupal 11.3.x. Verified against 11.3.8 + pwa module (node 3220515) where pwa.config registers its route with the systemAdminMenuBlockPage controller, causing hasAccessToChildMenuItems() to re-enter itself for the same plugin ID before the first call returns. Under PHP 8.3's stricter 8MB zend.max_allowed_stack_size, this exhausts the stack and returns a 504 on every /admin page load.
The guard unsets the plugin ID on all return paths so it does not leak across separate access checks. The upstream MR !9794 avoids the recursion via early-exit but does not explicitly detect it — comment #17 (mstrelan) notes recursion detection is still needed. This patch fills that gap.
Attaching patch against 11.3.x. A functional test covering the self-referencing menu route scenario still needs to be added.
Comment #20
smustgrave commentedNot sure this hits critical so lowered it to least major. But fixes need to be against main