Problem/Motivation
After updating to Drupal 10.3, I get the following error when trying to visit any page on my site:
Error: Maximum call stack size of 8355840 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion? in Drupal\Component\DependencyInjection\Container->get() (line 129 of core/lib/Drupal/Component/DependencyInjection/Container.php).
Drupal\Component\DependencyInjection\Container->get('cache_context.user.is_super_user') (Line: 222)
Drupal\Core\Cache\Context\CacheContextsManager->getService('user.is_super_user') (Line: 184)
Drupal\Core\Cache\Context\CacheContextsManager->optimizeTokens(Array) (Line: 110)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys(Array) (Line: 242)
Drupal\Core\Cache\VariationCache->createCacheIdFast(Array, Object) (Line: 173)
Drupal\Core\Cache\VariationCache->getRedirectChain(Array, Object) (Line: 35)
Drupal\Core\Cache\VariationCache->get(Array, Object) (Line: 80)
Drupal\Core\Session\AccessPolicyProcessor->processAccessPolicies(Object) (Line: 126)
Drupal\Core\Session\PermissionsHashGenerator->getCacheableMetadata(Object) (Line: 53)
Drupal\Core\Cache\Context\AccountPermissionsCacheContext->getCacheableMetadata(NULL) (Line: 184)
Drupal\Core\Cache\Context\CacheContextsManager->optimizeTokens(Array) (Line: 110)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys(Array) (Line: 219)
Drupal\Core\Cache\VariationCache->createCacheId(Array, Object) (Line: 57)
Drupal\Core\Cache\VariationCache->set(Array, Object, Object, Object) (Line: 94)
Drupal\Core\Session\AccessPolicyProcessor->processAccessPolicies(Object) (Line: 126)
Drupal\Core\Session\PermissionsHashGenerator->getCacheableMetadata(Object) (Line: 53)
Drupal\Core\Cache\Context\AccountPermissionsCacheContext->getCacheableMetadata(NULL) (Line: 184)
Drupal\Core\Cache\Context\CacheContextsManager->optimizeTokens(Array) (Line: 110)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys(Array) (Line: 219)
Drupal\Core\Cache\VariationCache->createCacheId(Array, Object) (Line: 57)
Drupal\Core\Cache\VariationCache->set(Array, Object, Object, Object) (Line: 94)
Drupal\Core\Session\AccessPolicyProcessor->processAccessPolicies(Object) (Line: 126)
Drupal\Core\Session\PermissionsHashGenerator->getCacheableMetadata(Object) (Line: 53)
Drupal\Core\Cache\Context\AccountPermissionsCacheContext->getCacheableMetadata(NULL) (Line: 184)
Drupal\Core\Cache\Context\CacheContextsManager->optimizeTokens(Array) (Line: 110)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys(Array) (Line: 219)
Drupal\Core\Cache\VariationCache->createCacheId(Array, Object) (Line: 57)
Drupal\Core\Cache\VariationCache->set(Array, Object, Object, Object) (Line: 94)
Drupal\Core\Session\AccessPolicyProcessor->processAccessPolicies(Object) (Line: 126)
Drupal\Core\Session\PermissionsHashGenerator->getCacheableMetadata(Object) (Line: 53)
Drupal\Core\Cache\Context\AccountPermissionsCacheContext->getCacheableMetadata(NULL) (Line: 184)
Drupal\Core\Cache\Context\CacheContextsManager->optimizeTokens(Array) (Line: 110)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys(Array) (Line: 219)
Drupal\Core\Cache\VariationCache->createCacheId(Array, Object) (Line: 57)
Drupal\Core\Cache\VariationCache->set(Array, Object, Object, Object) (Line: 94)
The following part of the call stack is being repeated indefinitely:
Drupal\Core\Session\AccessPolicyProcessor->processAccessPolicies(Object) (Line: 126)
Drupal\Core\Session\PermissionsHashGenerator->getCacheableMetadata(Object) (Line: 53)
Drupal\Core\Cache\Context\AccountPermissionsCacheContext->getCacheableMetadata(NULL) (Line: 184)
Drupal\Core\Cache\Context\CacheContextsManager->optimizeTokens(Array) (Line: 110)
Drupal\Core\Cache\Context\CacheContextsManager->convertTokensToKeys(Array) (Line: 219)
Drupal\Core\Cache\VariationCache->createCacheId(Array, Object) (Line: 57)
Drupal\Core\Cache\VariationCache->set(Array, Object, Object, Object) (Line: 94)
Steps to reproduce
Might be a combination of this core version with certain custom/contrib modules or config, but I haven't been able to figure that out.
Proposed resolution
I was able to come up with a workaround: in AccessPolicyProcessor::processAccessPolicies(), if the resulting CacheableMetadata contains the 'user.permissions' cache context, remove it. This cache key invokes PermissionsHashGenerator::getCacheableMetadata(), which in turn invokes AccessPolicyProcessor::processAccessPolicies(), creating an infinite loop.
Remaining tasks
Find a better fix if necessary.
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3461270
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 #3
dieterholvoet commentedComment #4
cilefen commentedIs xdebug enabled? I remember there were issues with that, although this of course may be unrelated.
Comment #5
dieterholvoet commentedYes, Xdebug is enabled.
Comment #6
dieterholvoet commentedOh and might be worth mentioning, the
user.permissionscache context is attached to the role entity, which at some point is added as cacheable dependency.Comment #7
smustgrave commentedMR should be updated for 11.x
Nothing major stuck out but definitely seems like something that will need test coverage
Comment #8
geek-merlin@Dieter
I debugged a similar thing lately, it looks like the new permission negitiation code is not robust against some config override cacheability.
Can you
grep "implements ConfigFactoryOverrideInterface" modules?Comment #9
dieterholvoet commentedThat's it! The following class in my custom code seems to be the culprit. I don't think I'm doing anything wrong there though?
Comment #10
geek-merlinYo! I made the same omission in translation_bliss module, now fixed:
You need a $name check in getCacheableMetadata.
That said, imho it's still a core bug if it WSODs on too much config cachability.
Comment #11
dieterholvoet commentedYou're right, that fixes it for me. Thanks!