Problem/Motivation

Facing the following fatal error

In Container.php line 147:
                                                                               
  Circular reference detected for service "language_manager", path: "language  
  _request_subscriber -> language_manager -> config.factory -> symfony_mailer  
  .config_override -> plugin.manager.email_builder -> entity_type.manager ->   
  string_translation -> string_translator.locale.lookup".                      
                                                         

Steps to reproduce

Given that the "Drupal Symfony Mailer" was installed
And configured in a multilingual Drupal 10 website
When the admin install or uninstall modules
Then the "Circular reference detected for service" fatal error shows up

Proposed resolution

Manage the Circular reference of services in other ways

Remaining tasks

  • File an issue
  • Patch/MR fix
  • Test
  • Review

User interface changes

  • N/A

API changes

  • N/A

Data model changes

  • N/A
Command icon 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

Rajab Natshah created an issue. See original summary.

rajab natshah’s picture

Issue summary: View changes
mytungsten’s picture

We are experiencing the same issue with a multilingual site on Drupal 10.

Circular reference detected for service "language_manager", path: "language_request_subscriber -> language_manager -> config.factory -> symfony_mailer.config_override -> plugin.manager.email_builder -> entity_type.manager -> string_translation -> string_translator.locale.lookup"

weseze’s picture

Priority: Normal » Major

I have the same problem on a fresh install for Drupal 9.5.
Marking as major since we can no longer install this module.

rajab natshah’s picture

Issue summary: View changes
tichris59’s picture

Same problem here with a multilingual site in drupal 10.0.9 when I enabled the module.

adambraun’s picture

rolling back to 2479bcc8 resolved it for me. Looks like the fixes for https://www.drupal.org/project/symfony_mailer/issues/3367047 caused the issue

nonom’s picture

The issue persists in Drupal 10.1.0 for a multilingual profile installation.

rajab natshah’s picture

Yes, you are right, Martinez

Drupal ~10.1.0 for a multilingual profile installation

rajab natshah’s picture

Issue summary: View changes
adamps’s picture

As far as I can see, the only part of the loop that we can break is this:
symfony_mailer.config_override -> plugin.manager.email_builder

MailerConfigOverride could fetch the email builder manager to a local variable inside buildCache().

I'm not able to test this as I don't have any multilingual sites, so I hope someone else can help.

rajab natshah’s picture

Priority: Major » Critical

When the local module is enabled
And the Drupal Symfony Mailer module is enabled
And trying to install any other modules
Then the following fatal error will show up

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

Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "language_manager", path: "language_request_subscriber -> language_manager -> config.factory -> symfony_mailer.config_override -> plugin.manager.email_builder -> entity_type.manager -> string_translation -> string_translator.locale.lookup". in Drupal\Component\DependencyInjection\Container->get() (line 147 of core/lib/Drupal/Component/DependencyInjection/Container.php).
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 440)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 273)
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 440)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 440)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 440)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 440)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 273)
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 440)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 440)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters() (Line: 237)
Drupal\Component\DependencyInjection\Container->createService() (Line: 177)
Drupal\Component\DependencyInjection\Container->get() (Line: 105)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 992)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 816)
Drupal\Core\DrupalKernel->updateModules() (Line: 608)
Drupal\Core\Extension\ModuleInstaller->updateKernel() (Line: 244)
Drupal\Core\Extension\ModuleInstaller->install() (Line: 83)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->install() (Line: 175)
Drupal\system\Form\ModulesListConfirmForm->submitForm()
call_user_func_array() (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 597)
Drupal\Core\Form\FormBuilder->processForm() (Line: 325)
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: 583)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 54)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->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: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
Drupal\Core\DrupalKernel->handle() (Line: 19)
rajab natshah’s picture

Status: Active » Needs work
rajab natshah’s picture

Tested:
Only for Drupal 10 and Interface Translation + Language + Configuration Translation + Content Translation
And only when having two or more languages.

Not having the issue in Drupal 9

metallized’s picture

Status: Needs work » Needs review

As far as I can see, the only part of the loop that we can break is this:
symfony_mailer.config_override -> plugin.manager.email_builder

MailerConfigOverride could fetch the email builder manager to a local variable inside buildCache().

I'm not able to test this as I don't have any multilingual sites, so I hope someone else can help.

I tried to remove the plugin.manager.email_builder argument from symfony_mailer.config_override service, but the problem is that creating manually a instance of EmailBuilderManager needs a entityTypeManagerInterface argument, so now the circular reference is here, i think we must remove the EntityTypeManagerInterface from EmailBuilderManager.phpon line 72.

What i unsderstand is that the locale requiresentity_type.manager to load translated configs and this modules try to override those configs, requiring the same dependency entity_type.manager so the circular reference happens.

Don't know if is this correct, please review and let know how can i help you to make a fix, i am using Drupal 10 and localemodule.

rajab natshah’s picture

kreatil’s picture

Same or similar issue here after updating to 1.3.0-rc1 on Drupal 9.5.10 and PHP 8.1.16
Circular reference detected for service "entity_type.manager", path: "scheduler.manager -> date.formatter -> entity_type.manager -> string_translation -> string_translator.locale.lookup -> config.factory -> symfony_mailer.config_override -> plugin.manager.email_builder".

It took me four hours to figure this out, because at first I assumed the error was caused by scheduler. Now I can definitely break it down to the update from symfony_mailer-1.3.0-beta2 to symfony_mailer-1.3.0-rc1.

kreatil’s picture

This is the error message that I get when I try to clear caches via admin ui:

Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "language_manager", path: "language_manager -> config.factory -> symfony_mailer.config_override -> plugin.manager.email_builder -> entity_type.manager -> string_translation -> string_translator.locale.lookup". in Drupal\Component\DependencyInjection\Container->get() (line 147 of core/lib/Drupal/Component/DependencyInjection/Container.php).

Drupal\Component\DependencyInjection\Container->get('language_manager', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'string_translator.locale.lookup') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('string_translator.locale.lookup', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 273)
Drupal\Component\DependencyInjection\Container->createService(Array, 'string_translation') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('string_translation', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'entity_type.manager') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('entity_type.manager', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'plugin.manager.email_builder') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('plugin.manager.email_builder', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'symfony_mailer.config_override') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('symfony_mailer.config_override', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 273)
Drupal\Component\DependencyInjection\Container->createService(Array, 'config.factory') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('config.factory', 1) (Line: 434)
Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
Drupal\Component\DependencyInjection\Container->createService(Array, 'language_manager') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('language_manager') (Line: 613)
Drupal::languageManager() (Line: 479)
token_tokens('log', Array, Array, Array, Object)
call_user_func_array(Object, Array) (Line: 426)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'token') (Line: 405)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('tokens', Object) (Line: 433)
Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array) (Line: 359)
Drupal\Core\Utility\Token->generate('log', Array, Array, Array, Object) (Line: 241)
Drupal\Core\Utility\Token->doReplace(1, '[[log:created]] [[log:level]] [[log:channel]] [client: [log:ip], [log:user]] [log:location] [log:message]', Array, Array, Object) (Line: 191)
Drupal\Core\Utility\Token->replace('[[log:created]] [[log:level]] [[log:channel]] [client: [log:ip], [log:user]] [log:location] [log:message]', Array, Array, Object) (Line: 223)
Drupal\filelog\Logger\FileLog->render(3, '%type: @message in %function (line %line of %file).', Array) (Line: 159)
Drupal\filelog\Logger\FileLog->log(3, '%type: @message in %function (line %line of %file).', Array) (Line: 127)
Drupal\Core\Logger\LoggerChannel->log(3, '%type: @message in %function (line %line of %file).', Array) (Line: 70)
Drupal\Core\EventSubscriber\ExceptionLoggingSubscriber->onError(Object) (Line: 97)
Drupal\Core\EventSubscriber\ExceptionLoggingSubscriber->onException(Object, 'kernel.exception', Object)
call_user_func(Array, Object, 'kernel.exception', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.exception') (Line: 229)
Symfony\Component\HttpKernel\HttpKernel->handleThrowable(Object, Object, 1) (Line: 92)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
kreatil’s picture

Forwarding to dev-1.x 9b1509d does not solve it. Reverted to 1.3.0-beta2 to get rid of the issue.

anybody’s picture

Same here! Happened when we uninstalled the "reroute" module, but that may be unrelated.

trickfun’s picture

I think this error prevent sending mail with webform.
I can send mail with symfony test but not with webform.

I downgrade to 1.2.1 and all works fine.
Thank you

metallized’s picture

I think this is a temporary fix, please tell me what else we can do.

adamps’s picture

Status: Needs review » Needs work

@metallized Many thanks it is the only possible fix I can see - not just temporary.

Please can you put the formatting back how it was in symfony_mailer.services.yml and I will commit it (arguments all on a single line and in single quotes - it's the same in core.services.xml).

metallized’s picture

Done, have you read my comments on #15, maybe if we remove the depency on entity_type.manager in EmailBuilderManager:75 we can fixed?

metallized’s picture

Status: Needs work » Needs review
adamps’s picture

Thanks for the updated patch. Key question: does this fix the bug? Please can people try it and report back?

EmailBuilderManager uses entity_type.manager - if we remove that we will break some things.

My idea with the current patch is MailerConfigOverride will only load EmailBuilderManager when moduleHandler->isLoaded() is TRUE. For the very early calls to get config in middleware, the loading will be skipped. If it's still broken then we didn't wait long enough.

adamps’s picture

I installed some language modules on a test site, then I could hit this bug. I applied the patch from #26 and the problem was fixed. So the patch seems good for me.

kreatil’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm patch #25 fixes the error. Thank you @metallized

adamps’s picture

Status: Reviewed & tested by the community » Fixed

  • AdamPS committed 57bb8014 on 1.x authored by metallized
    Issue #3370109 by metallized, Rajab Natshah, AdamPS, kreatIL: Circular...
adamps’s picture

Great thanks everyone

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.