The website encountered an unexpected error. Try again later.

Error: Maximum call stack size of 8339456 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. Infinite recursion? in Drupal\Core\Entity\ContentEntityBase->Drupal\Core\Entity\{closure}() (line 1042 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

array_filter() (Line: 1041)
Drupal\Core\Entity\ContentEntityBase->getTranslationLanguages() (Line: 97)
Drupal\Core\Entity\EntityRepository->getTranslationFromContext() (Line: 1735)
_field_tokens() (Line: 503)
token_tokens()
call_user_func_array() (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 364)
Drupal\Core\Utility\Token->generate() (Line: 1097)
token_tokens()
call_user_func_array() (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 364)
Drupal\Core\Utility\Token->generate() (Line: 241)
Drupal\Core\Utility\Token->doReplace() (Line: 191)
Drupal\Core\Utility\Token->replace() (Line: 152)
Drupal\webform\WebformTokenManager->replace() (Line: 171)
Drupal\webform\WebformTokenManager->replaceNoRenderContext() (Line: 261)
Drupal\webform\Entity\WebformSubmission->label() (Line: 105)
Drupal\webform\Controller\WebformSubmissionViewController->title()
call_user_func_array() (Line: 58)
Drupal\Core\Controller\TitleResolver->getTitle() (Line: 880)
token_tokens()
call_user_func_array() (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 364)
Drupal\Core\Utility\Token->generate() (Line: 241)
Drupal\Core\Utility\Token->doReplace() (Line: 191)
Drupal\Core\Utility\Token->replace() (Line: 66)
Drupal\metatag\MetatagToken->replace() (Line: 791)
Drupal\metatag\MetatagManager->processTagValue() (Line: 634)
Drupal\metatag\MetatagManager->generateRawElements() (Line: 61)
Drupal\metatag\Plugin\Field\MetatagEntityFieldItemList::Drupal\metatag\Plugin\Field\{closure}() (Line: 637)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 48)
Drupal\metatag\Plugin\Field\MetatagEntityFieldItemList->computeValue() (Line: 32)
Drupal\metatag\Plugin\Field\MetatagEntityFieldItemList->ensureComputedValue() (Line: 43)
Drupal\metatag\Plugin\Field\MetatagEntityFieldItemList->getValue() (Line: 723)
Drupal\Core\Entity\ContentEntityBase->toArray() (Line: 950)

Comments

pemson18 created an issue. See original summary.

wmcmillian’s picture

StatusFileSize
new1.62 KB

I added a patch for this.

The issue is that the tokens function pulls in all of the tags attached to an entity and then runs token replace on them. If any of the tags reference via token any other tag, this causes a recursion.

This patch filters the tags being processed to only those being referenced by token and should ignore any tag value that references itself.

damienmckenna’s picture

Status: Active » Postponed (maintainer needs more info)

Do you have an example of a token that triggers the problem?

jmee’s picture

I ran into this behaviour when enabling the metatag module (2.2.0) on an existing Drupal 11 site where there are already over 7000 published nodes.

There were two situations where I was seeing this behaviour:

First, when I enabled maxlength trimming on the description field (so I disabled maxlength trimming to continue testing what was going on), and again when I used a custom field as the description value (specifically, I created a config for a specific node type and used a field on that node as the description value, so the token was just [node:field_description).

In both cases, I wasn't able to view any nodes / nodes of that type after saving the metatag configuration.

At first I was just getting a 500 server error and a blank page in the browser, without any messages in dblog, but eventually I did get the 'infinite recursion ?' error on the node (not sure why - I reloaded the page a few times and ran cron a few times).

I applied the patch attached to this issue, but I'm still getting the 'Error: Maximum call stack size' error in the browser and can't view the nodes.

roberto.muzzano’s picture

Hello.
Same error with Drupal 10.3.13, but also with Drupal 10.4.9.
The was applied correctly but seems to not work.

patches.lock.json does not exist. Creating a new patches.lock.json.
  - Resolving patches from root package.
  - Resolving patches from dependencies.
  - Removing drupal/metatag (2.2.0)
Deleting web/modules/contrib/metatag - deleted
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 1 install, 0 updates, 0 removals
  - Installing drupal/metatag (2.2.0): Extracting archive
  - Patching drupal/metatag
      - Found cached patch at /var/www/.cache/composer/patches/414d7bbc457a3580007f3541c977c4dd73f0e584b25b9762148abc33743aa4a8.patch
Package doctrine/annotations is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
93 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
phpstan/extension-installer: Extensions installed
  * Homepage: https://www.drupal.org/project/drupal
  * Support:
    * docs: https://www.drupal.org/docs/user_guide/en/index.html
    * chat: https://www.drupal.org/node/314178
 [success] Cache rebuild complete.

Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in /app/web/core/lib/Drupal/Core/Datetime/DateFormatter.php on line 114 Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in /app/web/core/lib/Drupal/Core/Session/SessionHandler.php on line 86 Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 20480 bytes) in /app/web/core/includes/errors.inc on line 26

damienmckenna’s picture

@Roberto: What patch are you applying?

roberto.muzzano’s picture

Hello @damienmckenna
This one https://www.drupal.org/files/issues/2025-08-08/fix_recursion.patch

Gathering patches for dependencies. This might take a minute.
- Installing drupal/metatag (2.2.0): Extracting archive
- Applying patches for drupal/metatag
https://www.drupal.org/files/issues/2025-08-08/fix_recursion.patch (Fix recursion (Drupal.org issue patch 2025-08-08))

roberto.muzzano’s picture

Hello, what kind of informations you need to check and fix the problem?
I can provide a repository with the problem.

pemson18’s picture

StatusFileSize
new32.53 MB

@damienmckenna This problem still persists here is the full error stack in the txt file attached, This happens on a webform save

roberto.muzzano’s picture

Hello @damienmckenna.
At the moment, I am unable to update the module from version 1.x to 2. I have tried 2.0.x, 2.1.x, and 2.2.x, but nothing works. Also this patch https://www.drupal.org/files/issues/2025-08-08/fix_recursion.patch seems to not fix the problem.
It is the last module that needs to be updated to move to Drupal version 10.4. x, I have tried debugging to find the problem, but without success, partly because the module is quite large.
As mentioned, I can provide a repository that shows the problem and the related database. I imagine this could be useful for debugging.
If anyone could take a look, it would be greatly appreciated.

damienmckenna’s picture

Please reach out to me via my contact page and I'll see if I can get to the bottom of this.

pemson18’s picture

pemson18’s picture

StatusFileSize
new30.59 MB